FirstOrDefault with a Not Found Element : FirstOrDefault « LINQ « C# / CSharp Tutorial






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.Take(0).FirstOrDefault();
        Console.WriteLine(name == null ? "NULL" : name);
    }
}








22.44.FirstOrDefault
22.44.1.Using FirstOrDefault
22.44.2.FirstOrDefault: get the first or the default
22.44.3.FirstOrDefault with a Not Found Element
22.44.4.FirstOrDefault returns null when an Element Is Found
22.44.5.FirstOrDefault with string operator
22.44.6.FirstOrDefault with Condition
22.44.7.Get a customer in Africa with FirstOrDefault