CSharp - Use FirstOrDefault operator with condition and an Element Is Not Found

Description

Use FirstOrDefault operator with condition and an Element Is Not Found

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program/*from   w  w w  .  j av a 2  s  .c  o  m*/
{
    static void Main(string[] args)
    {
      string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};

      string name = codeNames.FirstOrDefault(p => p.StartsWith("Z"));
      Console.WriteLine(name == null ? "NULL" : name);
    }
}

Result

Related Topic