I have
string[] pkgratio= "1:2:6".Split(':');
var items = pkgratio.OrderByDescending(x => x);
I want to select the middle value and have come up with this. Is this a correct way to select the second value in an IEnumberable?
pkgratio.Skip(1).Take(1).First();
While what you have works, the most straightforward way would be to use the array’s index and reference the second item (at index 1 since the index starts at zero for the first element):
pkgratio[1]A more complete example:
With an
IEnumerable<T>what you have works, or you could directly get the element using theElementAtmethod:Here is your sample as an
IEnumerable<string>. Note that theAsEnumerable()call is to emphasize the sample works against anIEnumerable<string>. You can actually useElementAtagainst thestring[]array result fromSplit, but it’s more efficient to use the indexer shown earlier.