CSharp examples for System.Collections.Generic:HashSet
To Hash Set Ignoring Duplicates
using System.Linq; using System.Text; using System.Globalization; using System.ComponentModel; using System.Collections.Generic; using System.Collections; public class Main{ public static HashSet<TItem> ToHashSetIgnoringDuplicates<TItem>(this IList<TItem> list) where TItem : IComparable<TItem> {//w w w. ja va2s. c o m var res = new HashSet<TItem>(); foreach (var item in list) { if (!res.Contains(item)) res.Add(item); } return res; } public static bool Contains<T>(this IEnumerable<T> me, Predicate<T> condition) { foreach (var val in me) { if (condition(val)) return true; } return false; } }