Comparison<T> 是一个delegate
几个常用的例子:
<1>
class Program
{
static void Main(string[] args)
{
int[] ia = new int[] { 1, 5, 2, 4, 3, 7, 6 };
Array.Sort(ia);
foreach (int i in ia)
Console.WriteLine(i);
}
}
<2>
class Program
{
static void Main(string[] args)
{
List<int> il = new List<int>(){1,3,4,2,6,7,5};
il.Sort();
foreach (int i in il)
Console.WriteLine(i);
}
<3>升序
class Program
{
private static int Cmp(int x, int y)
{
if(x == y)
return 0;
else if(x < y) return -1;
else return 1;
}
static void Main(string[] args)
{
List<int> il = new List<int>(){1,3,4,2,6,7,5};
il.Sort(Cmp);
foreach (int i in il)
Console.WriteLine(i);
}
class Program
{
private static int Cmp(int x, int y)
{
if(x == y)
return 0;
else if(x < y) return -1;
else return 1;
}
static void Main(string[] args)
{
int[] intArray = new int[]{1,3,4,2,6,7,5};
Array.Sort(intArray, Cmp);
foreach (int i in intArray)
Console.WriteLine(i);
}
}
分享到:
相关推荐
用函数模板方式设计一个函数模板sort<T>,采用直接插入排序方式对数据进行 排序,并对整数序列和字符序列进行排序
对你很有用的哈 接口IComparer<T>比较器关于排序Sort()方法
List<T>.Sort 方法 (IComparer<T>)的方法解释地址如下: http://msdn.microsoft.com/zh-cn/library/234b841s(v=vs.110).aspx 使用指定的比较器对整个 List<T> 中的元素进行排序。 命名空间: System....
List<T>类几种排序方法比较灵活 可以根据自己的需要 选用合适的方法
精华志 C#_List_<T>+Find+Exists+FindAll+Sort用法+范例 京华志&精华志出品 分享资源 C# ASP.NET SQL DBA 源码
charset=gb2312" /><br><title>test</title><br></head><br><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"><br><table height=1000><br><tr><td>dddd</td></tr><br></table><br></body><br...
(4KB)<END><br>99,tokeniterator.zip<br>Token Iterator provides an easy to use, familiar, and customizable way in which to go through the tokens contained in a string (7KB)<END><br>100,stdsort.zip<br>An...
We couldn't think of how to describe it properly, but 下载 it and try it<END><br>57,basicreg.zip<br>Basic Save and Retrieve Functions<END><br>58,proguse.zip<br>Keep Track of a Programs Usage<END><br>...
noreturn.zip<br>Disable the Return Key in a TextBox<END><br>60,entertab.zip<br>Use the Enter Key Like a Tab<END><br>61,detenter.zip<br>Detect When the User Presses Enter<END><br>62,prntscrn.zip<br>...
When you click on a table, it lists all <END><br>38,3a.zip<br>An Inventory System, you can add, edit, sort, find, delete, print, change your password and create a backup of your database<END><br>39,A...
Supports font option for the Document Selector.<br>* Supports 'Sort' button on the Window List.<br>* Supports 'Copy Name' button on the Window List.<br>* Search Document command could omit some words....
<END><br>34 , vertmenu.zip<br>When we first came across this, we couldn't believe its free! It mimics the Microsoft Outlook's Vertical Menu bar which appears on the left of the screen<END><br>35 , ...
LinearList<T>& Sort(void); /*关于前移和后移*/ void Reset(void) { current = 1; } //置current为0 T Current(void) { return element[current-1]; }//返回当前元素 bool End(void);//当且仅当当前元素为表...
public static void Sort<T>(IList<T> sortArray, Func<T, T, bool> comparsion) 这个方法的文档说明,conparsion 必须引用一个方法,该方法带有两个参数,如果第一个参数的值“小于”第二个参数,就返回true 。 ...
- <member name="T:Pic_Chart_Load.Print_Mess"> <summary>打印类</summary> <remarks /> </member> - <member name="M:Pic_Chart_Load.UpLoad_data_Insert.Return_Arr_OneS_data_by_DataGridView(System....
4.3 System.Linq.Lookup <TKey,TElement> 10 4.4 System.Linq.Expressions.Expression 10 5 接口 10 5.1 IEnumerable 、IEnumerator 10 5.1.1 正常使用 10 5.1.2 C#的 yield 12 5.2 IEnumerable <T> 12 5.3 ...
如qsort 等函数需要函数指针才能回调 用此函数库可以将成员函数指针转为普通函数指针 ... *static_cast<const T*>(a)-*static_cast<const T*>(b) : *static_cast<const T*>(b)-*static_cast<const T*>(a); }
Usage: rar <command> -<switch 1> -<switch N> <archive> <files...> <@listfiles...> <path_to_extract\> <Commands> a Add files to archive c Add archive comment ch Change archive parameters cw Write...
<bag id=pPage><we name=name>@{pPage:name},"@{item:name}"</we></bag> </if> </for> </chtml>[@{pPage:name}] 空数组直接输出: [] 下边将结合实例进行学习 6.3.1 输出Bag中的一条记录 闭合的json格式内容 ...