Returns arr[index] or, if index is out of bounds, arr.Last() - CSharp System

CSharp examples for System:Array Index

Description

Returns arr[index] or, if index is out of bounds, arr.Last()

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w  ww .jav  a  2 s . c o m*/

public class Main{
        /// <summary>
      /// Returns arr[index] or, if index is out of bounds, arr.Last()
      /// </summary>
      public static T GetMax<T>(this T[] arr, uint index)
      {
         if (index >= arr.Length)
         {
            index = (uint) (arr.Length - 1);
         }
         return arr[index];
      }
}

Related Tutorials