Blog.Mobile.Components.EnumerableExtensions.IndexOf C# (CSharp) Method

IndexOf() public static method

Returns the index of the specified object in the collection.
public static IndexOf ( this self, object obj ) : int
self this The self.
obj object The object.
return int
        public static int IndexOf(this IEnumerable self, object obj)
        {
            var index = -1;

            var enumerator = self.GetEnumerator();
            enumerator.Reset();
            var i = 0;
            while (enumerator.MoveNext())
            {
                if (enumerator.Current == obj)
                {
                    index = i;
                    break;
                }

                i++;
            }

            return index;
        }
    }
EnumerableExtensions