I want to use the .net LINQ GroupBy
method to group data points by x and y co-ordinates. I wasn't sure how to combine these x and y co-ordinates into a single entity to group on.
First, I tried combining them into an array of two elements. This didn't work, I believe, because even when they contain the same two numbers, two arrays aren't the same array.
Second, I tried converting them to strings and concatenating them like so: groupedData = data.GroupBy(a => a.x.ToString() + "," + a.y.ToString());
This appears to work, but it is obviously inefficient as the string conversion should be unnecessary.
What is a better way to do what I want to accomplish, preferably without using anonymous types?
Note: I must do this with .net 3.5.
Edit: This question is, indeed, almost exactly the same as the one it is marked as a duplicate of. However, the original question doesn't ask how to do this without using anonymous types and doesn't have the constraint that it has to work in .net 3.5.