First with string method : First « LINQ « C# / C Sharp






First with string method

 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};

        string name = presidents.First(p => p.StartsWith("H"));
        Console.WriteLine(name);
    }
}

 








Related examples in the same category

1.Use First, Last with expression
2.retrieves all strings in an array whose length matches that of the shortest string
3.Use First to return the first matching element as a Product
4.First operator