Get last element in an array in CSharp

Description

The following code shows how to get last element in an array.

Example


/*  w ww  . j av  a2s .  c  o  m*/
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};

        string name = presidents.Last();
        Console.WriteLine(name);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ