Removes the first occurrence of a specific object from the System.Collections.IList. Deals with null IList - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Removes the first occurrence of a specific object from the System.Collections.IList. Deals with null IList

Demo Code


using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/*  w  ww.  j a v  a  2s  .c  o  m*/
using Cirrious.CrossCore.Platform;

public class Main{
        /// <summary>
        /// Removes the first occurrence of a specific object from the System.Collections.IList.
        /// Deals with null IList
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="valueToRemove">The value to remove.</param>
        public static void SafeRemove(this IList source, object valueToRemove)
        {
            if (source != null)
                source.Remove(valueToRemove);
        }
}

Related Tutorials