Get Free Value Index in an array - CSharp System

CSharp examples for System:Array Index

Description

Get Free Value Index in an array

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w  w  w  .  j a  v a 2s . c o m*/

public class Main{
    public static uint GetFreeValueIndex<T>(this T[] arr)
         where T : struct
      {
         uint i = 0;
         for (; i < arr.Length; i++)
         {
            if (arr[i].Equals(default(T)))
            {
               return i;
            }
         }
         return i + 1;
      }
}

Related Tutorials