CSharp - Use FirstOrDefault operator with condition

Description

Use FirstOrDefault operator with condition

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program/*from   w  w  w . j  a v  a2 s. com*/
{
    static void Main(string[] args)
    {
        string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
        string name = codeNames.FirstOrDefault(p => p.StartsWith("B"));
        Console.WriteLine(name == null ? "NULL" : name);
    }
}

Result

Related Topic