Get First Or Default on an array in CSharp

Description

The following code shows how to get First Or Default on an array.

Example


// ww  w .  j a  v a2  s.co m
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"HTML", "HTML5", "Apple", "CSS", "CSS3", "Java"};
        string name = presidents.FirstOrDefault();
        Console.WriteLine(name == null ? "NULL" : name);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ