[英]c# sort a list by a column alphabetically
我定义了一个类,并将该类的记录写到列表中。 在编写错误报告之前,无法对列表进行排序。 我试图在编写错误报告之前按'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.Sort();
排序方法什么也不返回。 它只是对列表进行排序。
其次,如果要基于属性排序,请执行此操作
List<Types> sortedlist = List1.OrderBy(x => x.finderror).ToList();
我认为您想要List1 = List1.OrderBy( x => x.finderror ).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.