C#按字母顺序对列表进行排序 [英] c# sort a list by a column alphabetically

查看:653
本文介绍了C#按字母顺序对列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个类,并将该类的记录写到列表中.在编写错误报告之前,无法对列表进行排序.我试图在编写错误报告之前按'finderror'类型按字母顺序对列表进行排序,以便在错误报告中对列表进行排序和更有条理. 这是课程:

I have a class defined and I write records to this class to a List. Having trouble sorting the list before I write an error report. I'm trying to sort the list alphabetically by the 'finderror' type before the error report is written so that the list is sorted and more organized in the error report. Here is the class:

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; }

}

如果我写这篇文章,会出现以下错误:

If I write this, I get the following error:

    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>'

如何按字母顺序按列表中的"finderr"列进行排序.

How do i sort by the 'finderror' column in the list alphabetically.

推荐答案

我认为您要List1 = List1.OrderBy( x => x.finderror ).ToList();

这篇关于C#按字母顺序对列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆