c#按字母顺序按列对列表排序
我定义了一个类,并将该类的记录写入列表。在我写错误报告之前排序列表有困难。在编写错误报告之前,我尝试按“finderror”类型的字母顺序对列表进行排序,以便在错误报告中对列表进行排序和更有序的组织。 下面是课堂:c#按字母顺序按列对列表排序,c#,sorting,collections,C#,Sorting,Collections,我定义了一个类,并将该类的记录写入列表。在我写错误报告之前排序列表有困难。在编写错误报告之前,我尝试按“finderror”类型的字母顺序对列表进行排序,以便在错误报告中对列表进行排序和更有序的组织。 下面是课堂: public class types { public types() { } public string person { get; set; } public string state { get; set; } public string pho
public class types
{
public types() { }
public string person { get; set; }
public string state { get; set; }
public string phone# { get; set; }
public string finderror { get; set; }
}
如果我这样写,我会得到以下错误:
List1 = List1.Sort();
List1 is a global list I declared before my main.
Error-Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<types>'
List1=List1.Sort();
List1是我在main之前声明的全局列表。
错误无法将类型“void”隐式转换为“System.Collections.Generic.List”
如何按列表中“finderror”列的字母顺序进行排序 首先,它只是
List1.Sort();
排序方法不返回任何内容。它只是对列表进行排序
其次,如果要基于属性进行排序,请执行以下操作
List<Types> sortedlist = List1.OrderBy(x => x.finderror).ToList();
List-sortedlist=List1.OrderBy(x=>x.finderror.ToList();
首先,它只是
List1.Sort();
排序方法不返回任何内容。它只是对列表进行排序
其次,如果要基于属性进行排序,请执行以下操作
List<Types> sortedlist = List1.OrderBy(x => x.finderror).ToList();
List-sortedlist=List1.OrderBy(x=>x.finderror.ToList();
我想您需要List1=List1.OrderBy(x=>x.finderror.ToList()代码>我想您需要List1=List1.OrderBy(x=>x.finderror.ToList()代码>只需使用List1.Sort()代码>无任何分配。此方法将对列表进行排序,不会返回任何值。所以你没有什么可分配的。粘贴List1声明的代码。只需使用List1.Sort()代码>无任何分配。此方法将对列表进行排序,不会返回任何值。所以你没有什么可分配的。粘贴List1声明的代码。