CSharp examples for System.Collections.Generic:IList
Adds an item to list if it is not already in the list. Deals with null IList
using System.Linq; using System.Collections.Generic; using System.Collections; using System;//www. j a va 2s. c om using Cirrious.CrossCore.Platform; public class Main{ /// <summary> /// Adds an item to list if it is not already in the list. /// Deals with null IList /// </summary> /// <param name="source">The source.</param> /// <param name="itemToAdd">The item to add.</param> public static void SafeAddMissing(this IList source, object itemToAdd) { if (source == null) return; if (!source.Contains(itemToAdd)) source.Add(itemToAdd); } }