【问题标题】:c# sort a list by a column alphabeticallyc# 按字母顺序对列表进行排序
【发布时间】:2013-05-02 02:27:36
【问题描述】:

我定义了一个类,并将该类的记录写入一个列表。在我编写错误报告之前无法对列表进行排序。我试图在编写错误报告之前按“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>'

如何按字母顺序对列表中的“findererror”列进行排序。

【问题讨论】:

标签: c# sorting collections


【解决方案1】:

首先它只是

List1.Sort();

排序方法不返回任何内容。它只是对列表进行排序。

其次,如果您想根据属性进行排序,请执行此操作

List<Types> sortedlist = List1.OrderBy(x => x.finderror).ToList();

【讨论】:

    【解决方案2】:

    我想你想要List1 = List1.OrderBy( x =&gt; x.finderror ).ToList();

    【讨论】:

      猜你喜欢
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多