Index Of element in an array - CSharp System

CSharp examples for System:Array Index

Description

Index Of element in an array

Demo Code


using System.Runtime.InteropServices;
using System.Collections.Generic;
using System;//from   w w w.j a va2s. c  o  m

public class Main{
        public static int IndexOf<T>(this T[] array, T item) {
            for (var i = 0; i < array.Length; ++i) {
                if (EqualityComparer<T>.Default.Equals(array[i], item)) {
                    return i;
                }
            }
            return -1;
        }
}

Related Tutorials