C#帮助:对C#中的对象列表排序 [英] C# Help: Sorting a List of Objects in C#

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

问题描述


可能的重复项

使用预定义的排序值列表对对象排序

排序C#中的对象列表



public class CarSpecs
{

    public CarSpecs()
    {
    }

    private String _CarName;
    public String CarName
    {
        get { return _CarName; }
        set { _CarName = value; }
    }



    private String _CarMaker;
    public String CarMaker
    {
       get { return _CarMaker;}
       set { _CarMaker = value; }
    }


    private DateTime _CreationDate;
    public DateTime CreationDate
    {
        get { return _CreationDate; }
        set { _CreationDate = value; }
    }
}

这是一个列表,一个有效的方法来排序这个列表 List< CarSpecs> CarList ,包含6(或任何整数)汽车,由汽车制造日期。我打算做泡泡排序,但会工作吗?任何帮助?

This is a list and I am trying to figure out an efficient way to sort this list List<CarSpecs> CarList, containing 6(or any integer amount) Cars, by the Car Make Date. I was going to do Bubble sort, but will that work? Any Help?

感谢

推荐答案

CarList = CarList.OrderBy( x => x.CreationDate ).ToList();

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

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