c# - Obtain the result in easier way -
I need to include alternate elements in contrast to the original array.
For example: an array containing elements {12,56,67}
I need to keep the array behind to get {67,12} ({67,56,12}, then alternate elements mean {67, 12})
I need to do this in C #
If you use C # 3 , Try this:
int [] array = {1,2,3,4,5,6}; Var x = array.Reverse (). Where ((n, i) => i% 2! = 0); Where is an extension method (new in C # 3.0), which is part of the convenience of a language called LINQ. It filters the sequence on an estimate basis. In the sample given above, n is the element of the sequence and I have zero based indices of the element in order. Both are strongly typed I'm telling that the indicator of the element is not directly aliquot from 2, so what we're saying is reverse the list and select its weird elements.
Not the most efficient solution, but concise and concise.
Comments
Post a Comment