首页 > 编程语言 > 详细

C# 中 List.Sort运用(IComparer<T>)排序用法

时间:2017-06-19 10:44:57      阅读:408      评论:0      收藏:0      [点我收藏+]
        /// <summary>
        /// 比较人物类实例大小,实现接口IComparer
        /// </summary>
        public class InternetProtocolComparer : IComparer<InternetProtocol>
        {
            public int Compare(InternetProtocol x, InternetProtocol y)
            {
                if (x == null)
                {
                    if (y == null)
                        return 0;
                    else
                        return -1;
                }
                else
                {
                    if (y == null)
                        return 1;
                    else
                    {

  

              if (string.IsNullOrWhiteSpace(x.IP) || string.IsNullOrWhiteSpace(y.IP))
                return 0;

                        int xIP = int.Parse(x.IP.Replace(".", ""));
                        int yIP = int.Parse(y.IP.Replace(".", ""));

                        int retval = yIP.CompareTo(xIP);

                        return retval;
                    
                    }
                }
            }
        }

  参考地址:http://blog.csdn.net/kongwei521/article/details/12133377

C# 中 List.Sort运用(IComparer<T>)排序用法

原文:http://www.cnblogs.com/louby/p/7047537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!