Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#按字母顺序按列对列表排序_C#_Sorting_Collections - Fatal编程技术网

c#按字母顺序按列对列表排序

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

我定义了一个类,并将该类的记录写入列表。在我写错误报告之前排序列表有困难。在编写错误报告之前,我尝试按“finderror”类型的字母顺序对列表进行排序,以便在错误报告中对列表进行排序和更有序的组织。 下面是课堂:

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声明的代码。