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.jav  a2s . co m
{
    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