C# - Using LINQ to take two variables into a 2-dimensional array? -


I have a list of a "area" class that has two variables, "Start Location" and "End Location". I would like to add them both to a newly sorted 2 dimensional array where its location and an integer show that its beginning or end For example, if there are three field objects in the list I [area3]: startLocation = 5, endLocation = 7

[area 2]: startLocation = 3, endLocation = 5

[area3]: StartLocation = 8, endLocation = 9

I would like to look like a two-dimensional array (or list or similar) in a sequence:

[5] [5] [1]

[8] [1]

[9] [-1]

(preferably i I want to overlap to connect with, so add two different 5 to the array Will be given [5 0] ... but this is not very important)

I am currently going through each one using one of the regular ones and adding them one at a time This implementation is quite slow because I am working with large datasets, and I think LINQ is a more elegant / fast way to complete it.

Any suggestion would be appreciated.

You will need to define an auxiliary method that divides an area into two parts and It is easy to represent it using the new structure versus a 2D array

  structure data {public full value; Public Bull EastStart; } Public stable IEnumerable & lt; Data & gt; Split (this field area) {yield returns new data () (value = field. Start location, isStart = true}; yield returns new data () {value = field. End space, isStart = false};}  

Then you can break them using the following LINQ query and sort them.

List & lt; Region & gt; List = GetTheList (); Var query = list .SelectMany (x = & gt; x.Split ()). OrderB (x => x.Data);

Comments