A friend just asking me about how to access the LINQ return result collection with a specific array index. Most likely first thought is walk through the collection by foreach. But this might be resource hungry, especially the return collection is huge.
So, there is a quick function in the <IEnemerable> interface which can anwser this question and does not require the foreach loop... That is the System.IEnumerable.ElementAt method, and below is the quick sample code which would like to share it.
Int32[] source = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
IEnumerable<Int32> query =
from value in source
where value < 5
select value;
Console.WriteLine(query.ElementAt(2));
04b92914-8f57-4add-89cf-d07f7ed050cb|0|.0
Quick Tips
LINQ