c# - How to split array in two arrays? -
I have an array and it has to be divided into two:
Now: < / Strong> & nbsp; & Nbsp; & Nbsp; & Nbsp; <0> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
New_1: [0, 2, 4, 6, 8]
new_2: [1, 3, 5, 7, 9]
Then take an element and leave the next element. Very easy but how can I do with C #?
Thank you very much
You can use linq, and those elements You can get the array with even and weird indexes.
var new_1 = arr.Where ((c, i) => i% 2 == 0) .oir (); Var new_2 = arr.Where ((C, I) => I% 2! = 0) .Oir ();
You can get the index of the element of the collection and bet to check how much or odd the index is and get the array accordingly.
Countable. The method (IEnumerable, Func) filters the order of values based on an estimate. The index of each element is used in the argument of the ceremony function. The first argument of the mastermind represents the element to test. The second argument shows the zero-based indicator of the element within the source,
Comments
Post a Comment