I have the following List of object collection.
column1:
Point data type
x=10,y=20
I have filtered that Point column using linq ofType<Point>.
Var XYLocations = Source.Select(g => g.ofType<Point>).ToList();
Now XYLocations contains duplicates.
From that list, I want to use linq to convert the list to dictionary<Point,List<int>> in which point is the key key and the corresponding matching row indixes act as values.
Try something like this:
var xyLocations = //initialization
var dictionary = xyLocations
                     .Select((p, i) => new Tuple<Point, int>(p, i))
                     .GroupBy(tp => tp.Item1, tp => tp.Item2)
                     .ToDictionary(gr => gr.Key, gr => gr.ToList());
If you don't have Tuple you can use anonymous type instead:
var dictionary = xyLocations
                     .Select((p, i) => new {Item1 = p, Item2 = i})
                     .GroupBy(tp => tp.Item1, tp => tp.Item2)
                     .ToDictionary(gr => gr.Key, gr => gr.ToList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With