Add Distinct to ICollection - CSharp System.Collections

CSharp examples for System.Collections:ICollection

Description

Add Distinct to ICollection

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*from w w w. j  av a2s. c o m*/

public class Main{
        public static void AddDistinct(this ICollection<string> collection, string item)
        {
            if (!string.IsNullOrWhiteSpace(item) && !collection.Any(x => x == item))
                collection.Add(item);
        }
}

Related Tutorials