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






FirstOrDefault: get the first or the default

 

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);
    }
}

 








Related examples in the same category

1.use FirstOrDefault
2.FirstOrDefault with a Not Found Element
3.FirstOrDefault returns null when an Element Is Found
4.FirstOrDefault with string operator
5.FirstOrDefault with Condition