检查ac#list中的某些项是否相同
我想根据列表中的项目检查列表中的某些项目是否相同。
List 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; } }
现在,我想将所有VariantName和VariantValue与相同的GUID一起显示出来。
我怎样才能做到这一点?
试试这个
productDTOs.GroupBy(x => x.GUID,(key,item) => new { VariantName= item.Select(y=>y.VariantName), VariantValue = item.Select(y => y.VariantValue), }).ToList()