[英]Check if some items are same in a c# list
I want to check if some items are same in a list based on a item present in the list.我想根据列表中存在的项目检查列表中的某些项目是否相同。
List<ProductDetailDTO> productDTOs;
The ProductDetailDTO is - 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; }
}
Now, I want to display all VariantName and VariantValue with the same GUIDs together.现在,我想一起显示具有相同 GUID 的所有 VariantName 和 VariantValue。
How can I achieve this?我怎样才能做到这一点?
try with this试试这个
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.