Get Last Or Default with consitions in CSharp

Description

The following code shows how to get Last Or Default with consitions.

Example


using System;/*from   www . j  a v a 2 s  . c  o m*/
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"HTML", "HTML5", "CSS", "CSS3", "Java", "XML"};

        string name = presidents.LastOrDefault(p => p.StartsWith("Z"));
        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