Linq Groupby returns the original object

I need help filtering some data. I have a class of objects with three properties. In a collection of objects that I have, it may be a lot of overlap of the first properties Point3d. From this collection of matches I need to see whether the second property of unique values Tag. Finally, I need to define objects that Point3dmatch, and Tagsare different, using the third property, it Id(which is always unique).

class pmatch
{
    public string Point3d { get; set; }
    public string Tag { get; set; }
    public string Id { get; set; }
}

An example of what I'm looking for would be:

List<pmatch> dataset = new List<pmatch>
{
    new pmatch { Point3d = "1, 1, 1", Tag = "5", Id = "123" },
    new pmatch { Point3d = "1, 1, 1", Tag = "6", Id = "124" },
    new pmatch { Point3d = "1, 1, 2", Tag = "7", Id = "125" },
    new pmatch { Point3d = "1, 1, 2", Tag = "7", Id = "126" }
};

I need to identify Id's123 and 124 as their correspondence Point3ds, but they Tagsare not. I was able to identify these instances using LINQ:

var result = datalist.GroupBy(item => item.Point3d, item => item.Tag);
foreach (var group in result)
{
    Console.WriteLine(group.Key);
    var uniqueTags = group.Distinct().ToList();
    if (uniqueTags.Count > 1)
    {
        Console.WriteLine("Found mismatched tags");
        foreach (string Tag in group)
        {
            Console.WriteLine("  {0}", Tag);
        }
    }
}

Id, , . Id pmatch?

+4
1

:

var resultSet = 
       dataset.GroupBy(item => item.Point3d)
              .Where(group => group.Select(item => item.Tag)
                                   .Distinct()
                                   .Count() > 1)
              .ToDictionary(item => item.Key, item => item.ToList());

Id 123 124, Point3ds, , resultSet Dictionary<string, List<pmatch>>, pmatch.

+5

Source: https://habr.com/ru/post/1695657/


All Articles