The Last operator returns the last element of a sequence or the last element of a sequence matching a predicate.
The Last operator always returns exactly one element, or it throws an exception if there is no last element to return.
There are two prototypes we cover. The first Last Prototype
public static T Last<T>( this IEnumerable<T> source);
Using this prototype, the Last operator enumerates the input sequence named source and returns the last element of the sequence.
The second prototype of Last uses a predicate:
public static T Last<T>( this IEnumerable<T> source, Func<T, bool> predicate);
This version of the Last operator returns the last element it finds for which the predicate returns true.
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program//from w w w . j av a 2s. c o m { static void Main(string[] args) { string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"}; string name = codeNames.Last(); Console.WriteLine(name); } }