Returns the last element of the list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Returns the last element of the list.

Demo Code


using System.Collections.Generic;
using System;/*  w w  w  . j a  va 2 s  .  c  om*/

public class Main{
    /// <summary>
      ///     Returns the last element of the list.
      /// </summary>
      /// <typeparam name="T"></typeparam>
      /// <param name="list"></param>
      /// <returns></returns>
      public static T LastItem<T>(this List<T> list) {
         return list[list.Count - 1];
      }
}

Related Tutorials