扩展类

    public static class Extensions
    {
        //2016.1.18 start
        public static int toInt(this string str) {
            return Convert.ToInt32(str);
        }
        public static  bool IsNullOrEmpty(this string s)
        {
            return string.IsNullOrEmpty(s);
        }
    }
}

  

2016.2.26

增加泛型去重复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ssm.Helper
{
    public static class Extensions
    {
        //2016.1.18 start
        public static int toInt(this string str) {
            return Convert.ToInt32(str);
        }
        public static  bool IsNullOrEmpty(this string s)
        {
            return string.IsNullOrEmpty(s);
        }

        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;
                }
            }
        }
    }
}

  

posted @ 2016-01-18 14:10  少时不知贵  阅读(188)  评论(0编辑  收藏  举报