linq 的Distinct 扩展方法.

    List<miniclass> classs = new List<miniclass>();
            classs.Add(new miniclass()
                {
                    token = ",
                    id = "
                });

            classs.Add(new miniclass()
            {
                token = ",
                id = "
            });
            classs.Add(new miniclass()
            {
                token = ",
                id = "
            });

            var dx = classs.DistinctBy(x => x.id);

            Console.ReadKey();

dx就选出来2条.内容.根据x.id.

  public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
    {
      HashSet<TKey> seenKeys = new HashSet<TKey>();
      foreach (TSource element in source)
      {
        if (seenKeys.Add(keySelector(element)))
        {
          yield return element;
        }
      }
    }

]]>

上一篇:兼容ie\firefox\chrome的cursor


下一篇:stylus--css 框架使用方法