How to get first record using LINQ ?

First record of collection can be obtained using First() method .

Example :
Code :
string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
string startsWithO = strings.First(s => s[0] == 'o');
Console.WriteLine("A string starting with 'o': {0}", startsWithO);

Output :
A string starting with 'o': one

No comments:

Popular Posts