Ensures that the given array has at least the given size and resizes if its too small - CSharp System

CSharp examples for System:Array Element

Description

Ensures that the given array has at least the given size and resizes if its too small

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from   ww  w . j a  v a2s  . c  om

public class Main{
        /// <summary>
      /// Ensures that the given array has at least the given size and resizes if its too small
      /// </summary>
      public static void EnsureSize<T>(ref T[] arr, int size)
      {
         if (arr.Length < size)
         {
            Array.Resize(ref arr, size);
         }
      }
}

Related Tutorials