FirstOrDefault: get the first or the default : FirstOrDefault « LINQ « C# / CSharp Tutorial






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

public class MainClass {
    public static void Main() {
        int[] numbers = { };

        int firstNumOrDefault = numbers.FirstOrDefault();

        Console.WriteLine(firstNumOrDefault);
    }
}








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