CSharp - Use Last operator with condition

Description

Use Last operator with condition

Demo

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

Result

This should return the last element in the input sequence that begins with the string "J".

Related Topic