I have a database that deconstructs an x,y coordinate pair table into specific dataitems.
Coordinate
{
int X,
int Y,
int Value
}
How do I rejoin these coordinates in Linq into a table? What if there are empty spaces in the Database (denoted by -):
Y
0 1 2
-------
0 | 4 6 7
X 1 | 9 - 7
2 | 6 3 5
How do I handle that in linq?
LINQ is generally good for working with structured (one-dimensional) data such as databases or XML files, but I don’t think it will help you when you need to create two-dimensional data structure.
If you just want to load the data into a 2D array, than it probably cannot get much nicer than the direct way of writing it (using
Maxextension method from LINQ to get the size):If you want to do it the other way round – to generate coordinates from a 2D array, then you can use LINQ’s
Enumerable.Rangeto generate indices of the 2D array andwhereto select elements that contain some actual value: