日期:2014-05-17 浏览次数:21177 次
using System.Linq;
List<int> list = new List<int>();
list.Add(1);
list.Add(3);
list.Add(5);
list.Add(1);
list.Add(5);
list=list.Distinct().ToList();
foreach (var value in list)
{
Response.Write(value + "<br />");
}
public static class DistinctExtensions
{
public static IEnumerable<T> Distinct<T, V>(this IEnumerable<T> source, Func<T, V> keySelector)
{
return source.Distinct(new CommonEqualityComparer<T, V>(keySelector));
}
public static IEnumerable<T> Distinct<T, V>(this IEnumerable<T> source, Func<T, V> keySelector, IEqualityComparer<V> comparer)
{
return source.Distinct(new CommonEqualityComparer<T, V>(keySelector, comparer));
}