如何对多维列表c#进行排序? [英] How to sort multidimensional list c#?

查看:107
本文介绍了如何对多维列表c#进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对多维List< T>进行排序? ? 


我有一个FormControl属性列表,填写如下(在循环中):


panel2Fields.Add(new Field(this .panel2.Controls [i] .Name,this.panel2.Controls [i] .Text,this.panel2.Controls [i] .TabIndex));


Field类需要三个参数,对于(在这种情况下)三个属性(不同类型:string和int),我想在第三个属性上对panel2Fields列表进行排序:TabIndex。

我理解它必须以某种方式完成IComparer接口,但不知道如何。

解决方案

你好,


 


我认为你可以按照这个
中的代码 List< T> .Sort Method(IComparer< T>)文件。


 


更改它们


public int Compare(Field x,Field y)

{


If(x.string> y.string)


返回0;


//在if部分你可以特别想要比较哪个值


 


 


最好的问候,


杰西


How do I sort a multidimensional List<T> ? 

I have a list of FormControl attributes, filled as follows (in a loop):

panel2Fields.Add(new Field(this.panel2.Controls[i].Name, this.panel2.Controls[i].Text, this.panel2.Controls[i].TabIndex));

The Field class takes three arguments, for (in this case) three properties (of different types: string and int) and I want to sort the panel2Fields list on the third of these properties: TabIndex.

I understand it must somehow be done with the IComparer interface but don't see how.

解决方案

Hello,

 

I think you can follow the codes in this List<T>.Sort Method (IComparer<T>) document.

 

Change them like

public int Compare(Field x, Field y)
{

If(x.string > y.string)

Return 0;

// in the if section you can special which value you want to compare

 

 

Best regards,

Jesse


这篇关于如何对多维列表c#进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆