zoukankan      html  css  js  c++  java
  • C# 中 List.Sort运用(IComparer<T>)排序用法

            /// <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

  • 相关阅读:
    2333
    STL string
    后缀自动机的应用
    省选一轮
    等价类计数问题(Polya定理和burnside引理)
    Prufer序列与树的计数(坑)
    分治算法
    生成函数
    莫队算法
    Xamarin 技术解析
  • 原文地址:https://www.cnblogs.com/louby/p/7047537.html
Copyright © 2011-2022 走看看