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

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

问题描述


可能显示的文件:

排序对象使用排序的值

C#帮助:排序在C#对象列表



双岗



http://stackoverflow.com/questions/925471/c-help-sorting-a-list-of-objects-in-c/925477#925477


< /块引用>

 公共类CarSpecs 
{

公共CarSpecs()
{
}

私人字符串_CarName;
公共字符串CarName
{
{返回_CarName; }
集合{_CarName =价值; }
}



私人字符串_CarMaker;
公共字符串的汽车制造商
{
{返回_CarMaker;}
集合{_CarMaker =价值; }
}


私人的DateTime _CreationDate;
公众的DateTime CreationDate
{
{返回_CreationDate; }
集合{_CreationDate =价值; }
}
}

这是一个名单,我想图出一个有效的方法排序这个列表列表< CarSpecs>卡洛斯,含6(或任意整数金额)汽车,由汽车制造日期。我打算做冒泡排序,而是将这项工作?任何帮助吗?



感谢


解决方案

 卡洛斯= CarList.OrderBy(X => x.CreationDate).ToList(); 


Possible Duplicates:
Sort objects using predefined list of sorted values
C# Help: Sorting a List of Objects in C#

Double Post

http://stackoverflow.com/questions/925471/c-help-sorting-a-list-of-objects-in-c/925477#925477

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

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?

Thanks

解决方案

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

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

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