[英]Check if some items are same in a c# list
我想根據列表中存在的項目檢查列表中的某些項目是否相同。
List<ProductDetailDTO> productDTOs;
ProductDetailDTO 是 -
public class ProductDetailDTO
{
public int ProductId { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public byte[] Image { get; set; }
public string Description { get; set; }
public string Brand { get; set; }
public string GUID { get; set; }
public string VariantName { get; set; }
public string VariantValue { get; set; }
public decimal Price { get; set; }
}
現在,我想一起顯示具有相同 GUID 的所有 VariantName 和 VariantValue。
我怎樣才能做到這一點?
試試這個
productDTOs.GroupBy(x => x.GUID,(key,item) => new
{
VariantName= item.Select(y=>y.VariantName),
VariantValue = item.Select(y => y.VariantValue),
}).ToList()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.