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
C# 中 List.Sort运用(IComparer<T>)排序用法的更多相关文章
- java中Collections.sort()方法实现集合排序
1.Integer/String泛型的List进行排序 List <Integer> integerlist = new ArrayList<Integer>(); //定 ...
- C++中使用sort对常见容器排序
本文主要解决以下问题 STL中sort的使用方法 使用sort对vector的排序 使用sort对map排序 使用sort对list排序 STL中sort的使用方法 C++ STL 标准库中的 sor ...
- Linux中cut,sort,uniq和wc的用法
一.cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对"行"来进行分析的,并不是整篇信息分析的.1.语法格式为:cut [-bn] [fil ...
- 【转载】C#中自定义Sort的排序规则IComparable接口
C#中的List集合在排序的时候,如果不使用Lambda表达式进行排序的话,一般调用Sort()方法进行排序,如果希望Sort()方法排序后的结果跟我们预想的效果一致或者按照我们自定义的规则排序,则需 ...
- C#中的IComparable 和 IComparer 接口,实现列表中的对象比较和排序
借豆瓣某博主的话先对这两个接口进行一个解释: IComparable在要比较的对象的类中实现,可以比较该对象和另一个对象 IComparer在一个单独的类中实现,可以比较任意两个对象. 如果已经支持 ...
- C# List.Sort与IComparer接口及Comparison委托应用于集合排序
C#里List.Sort的用法 using System; using System.Collections.Generic; using System.Linq; using System.Text ...
- 模拟javascript中的sort排序
一.javascript中sort对数据进行排序的原理 sort() 方法对数组的元素做原地的排序,并返回这个数组. sort 可能不是稳定的.默认按照字符串的Unicode码位点排序; 语法:arr ...
- 用Java集合中的Collections.sort方法对list排序的两种方法
用Collections.sort方法对list排序有两种方法第一种是list中的对象实现Comparable接口,如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- Java开发中使用sort排序
Java开发中使用sort排序 BaiduSpring https://baijiahao.baidu.com/s?id=1625440912158830354&wfr=spider& ...
随机推荐
- (原) windows下autohotkey的快捷键脚本编写
autohotkey 脚本很强大,可以接受传参.能各种程序逻辑控制.还可以把脚本转换成独立执行的EXE.(安装完后程序目录下有个小程序:Convert .ahk to .exe,直接UI上转换.)总之 ...
- 在IIS7上部署aspx网站
在IIS7上部署aspx网站 2016-12-06 1 示例代码 WebForm.aspx内容: <html> <head> <script language=" ...
- springboot+sqlite+maven+mybatis
https://blog.csdn.net/u012343297/article/details/79163977 ****************************************** ...
- jQuery实现radio第一次点击选中第二次点击取消功能(转)
转载自:http://www.jb51.net/article/113730.htm 由于项目的需求,要求radio点击两次后为取消状态,不方便修改为checkbox,可以用正面的方法实现. // j ...
- WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换
1 WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换 2012-12-18 17:27:04| 分类: Windows Phone 8|字号 订 ...
- [转]MySQL中int(11)最大长度是多少?
原文地址:https://blog.csdn.net/allenjay11/article/details/76549503 今天在添加数据的时候,发现当数据类型为 int(11) 时,我当时让用户添 ...
- 定位被选中的select
<script> var countryId = "{$user['country']}"; $("select[@name='country'] optio ...
- iOS美丽约网络请求分析
网络请求分析html, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin: 0px; padd ...
- selenium.common.exceptions.WebDriverException: Message: "Can't load the profile.
记录一下,Selenium在最新版本中修好了这个问题.运行CMD,然后输入 pip install -U selenium
- gdb基本命令(非常详细)
gdb基本命令 本文介绍使用gdb调试程序的常用命令. 主要内容: [简介] [举例] [其他] [简介] ============= GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具. ...