如何对多维列表c#进行排序? [英] How to sort multidimensional list 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。
你好,
我认为你可以按照这个
中的代码 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.
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屋!