请问在c#中List<T>中sort函数的用法是?

c#中List<T>中sort函数的用法是?


UYOU
浏览 1634回答 6
6回答

不负相思意

这里有个例子, 你可以把参数 sting换成的你的类型 stud然后相应用学号比较。private static int CompareDinosByLength(string x, string y){if (x == null){if (y == null){// If x is null and y is null, they're// equal.return 0;}else{// If x is null and y is not null, y// is greater.return -1;}}else{// If x is not null...//if (y == null)// ...and y is null, x is greater.{return 1;}else{// ...and y is not null, compare the// lengths of the two strings.//int retval = x.Length.CompareTo(y.Length);if (retval != 0){// If the strings are not of equal length,// the longer string is greater.//return retval;}else{// If the strings are of equal length,// sort them with ordinary string comparison.//return x.CompareTo(y);}}}参数就填这个方法名。

杨魅力

用orderBy试试:mlist.OrderBy(su => su.a).ThenBy(su=> su.b);

拉风的咖菲猫

s&nbsp;&nbsp;实际&nbsp;是一个二维指针,直接传到sort里类型不符,sort只接受一维指针作为参数,传二维指针是无论如何也达不到目的的,要使一个函数能接收二维指针,必须指明大小,如 void&nbsp;example(int&nbsp;a[][5]) 而sort当初这个接口设计的时候就没有考虑到二维指针,所以这里是行不通的。 PS:既然已经用了c++,C的一些东西能扔就扔,多用string,vector,list,还有些智能指针。少用些直接的指针,c++的指针出手一定是重量级的。

人到中年有点甜

sort(s,s+n,cmp);传入的参数是 s,可以理解为 str *,即 指向字符串的指针使用 sort 需要处理几个问题:1. ++操作;2. 比较;3. 赋值你对于第三个没有处理,假定有变量str a,b;a = b; // 这样是不可以的
打开App,查看更多内容
随时随地看视频慕课网APP