Trunc Values from generic array - CSharp System

CSharp examples for System:Array Element

Description

Trunc Values from generic array

Demo Code


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

public class Main{
    public static void TruncVals<T>(ref T[] arr)
         where T : struct
      {
         var lastIndex = arr.Length - 1;
         for (var i = 0; i <= lastIndex; i++)
         {
            if (arr[i].Equals(default(T)) && i != lastIndex)
            {
               Array.Resize(ref arr, i);
               break;
            }
         }
      }
}

Related Tutorials