Using First Function of Linq

Thsi VB sample code shows different Ways to retrive first element of an array using LINQ.

Dim names() As String = {"Hefin", "Abbas", "Mathew", "Sam", "Anthony"}

Dim first = names.First() 'Method One
Dim firstA = names.First(Function(n) n(0) = "A") 'Gets the first element that starts with "A"

'n(index) decides which character matches n(0) means first
Console.WriteLine("First Element is : " & first)
Console.WriteLine("First Element That Starts with A is : " & firstA)

Requires .net Framework 3.5

Regards Hefin Dsouza


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: