0

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 -

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.

How can I achieve this?

Suyash Gupta
  • 546
  • 10
  • 31
  • 2
    Have you posted same question here as well? https://stackoverflow.com/questions/52252391/display-fields-with-the-same-guids-together – ManishM Sep 10 '18 at 07:11

1 Answers1

2

try with this

productDTOs.GroupBy(x => x.GUID,(key,item) => new
            {
                VariantName= item.Select(y=>y.VariantName),
                VariantValue = item.Select(y => y.VariantValue),

            }).ToList()
mukesh kudi
  • 719
  • 6
  • 20