CSharp - First operator with condition

Description

First operator with condition

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program// ww w. j av a2s  . c o  m
{
    static void Main(string[] args)
    {
        string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
        
        string name = codeNames.First(p => p.StartsWith("J"));
        Console.WriteLine(name);
    }
}

Result

The following code should return the first element in the input sequence that begins with the string "J".

Related Topic