Determines the index of a specific item in the System.Collections.Generic.IList. Deals with null IList - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Determines the index of a specific item in the System.Collections.Generic.IList. Deals with null IList

Demo Code


using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/*w  ww  . ja  v  a 2 s. co m*/
using Cirrious.CrossCore.Platform;

public class Main{
        /// <summary>
        /// Determines the index of a specific item in the System.Collections.Generic.IList.
        /// Deals with null IList
        /// </summary>
        /// <typeparam name="T">The type of the elements of source</typeparam>
        /// <param name="source">The System.Collections.Generic.IList to check for index</param>
        /// <param name="value">The value to check with</param>
        /// <returns>The index of item if found in the list; otherwise, -1.</returns>
        public static int SafeIndexOf<T>(this IList<T> source, T value)
        {
            return source != null ? source.IndexOf(value) : -1;
        }
}

Related Tutorials