Suppose I have the following class:
public class Test{ public string Length { get; set; } public string Width { get; set; } public string Height { get; set; } public int Count { get; set; } public string Label { get; set; } }
And I would like to find elements that have the same value for length and label and count how many there are for each. So far, my code looks like this:
var dups = testlist.GroupBy(i => new { i.Length, i.Label }) .Where(g => g.Count() >= 1) .Select(g => new { Length = g.Key.Length, Label = g.Key.Label, Count = g.Count() });
But the problem is that the objects in var no longer have the width or height property (they do not exist in g.Key). Do I need to look for duplicates based on two properties while maintaining other properties as a result?
Tony
source share