Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 分类列表<;对象>;(n)与ThenBy_C#_List_Sorting_Asp.net 3.5 - Fatal编程技术网

C# 分类列表<;对象>;(n)与ThenBy

C# 分类列表<;对象>;(n)与ThenBy,c#,list,sorting,asp.net-3.5,C#,List,Sorting,Asp.net 3.5,我们使用的是nTiers,我有一个对象列表,我需要按一个属性排序,然后按另一个属性排序,我有以下内容,但我不知道如何使用然后按,我看到了列表的示例,但没有看到列表的示例 在调用ToList之前,您需要先调用,然后再调用: 列表分类列表= clients.OrderBy(o=>o.ClientOrder) .ThenBy(o=>o.ClientName) .ToList(); 仅适用于sIOrderedEnumerables是来自的返回类型,但一旦调用ToList,它就不再是IOrderedEn

我们使用的是nTiers,我有一个对象列表,我需要按一个属性排序,然后按另一个属性排序,我有以下内容,但我不知道如何使用
然后按
,我看到了
列表
的示例,但没有看到
列表
的示例


在调用
ToList
之前,您需要先调用
,然后再调用

列表分类列表=
clients.OrderBy(o=>o.ClientOrder)
.ThenBy(o=>o.ClientName)
.ToList();
仅适用于s
IOrderedEnumerable
s是来自的返回类型,但一旦调用
ToList
,它就不再是
IOrderedEnumerable
,而是
列表
,并且不实现
IOrderedEnumerable

,您可以将该类与
列表一起使用。排序

clients.Sort(new Comparison<Client>(
    (client1, client2) =>
    {
        // compare dates
        int result = client1.OrderDate.CompareTo(client2.OrderDate);
        // if dates are equal (result = 0)
        if(result == 0)
            // return the comparison of client names
            return client1.ClientName.CompareTo(client2.ClientName);
        else
            // otherwise return dates comparison
            return result;
    })
);
clients.Sort(新比较(
(客户端1、客户端2)=>
{
//比较日期
int result=client1.OrderDate.CompareTo(client2.OrderDate);
//如果日期相等(结果=0)
如果(结果==0)
//返回客户端名称的比较
返回client1.ClientName.CompareTo(client2.ClientName);
其他的
//否则返回日期比较
返回结果;
})
);
(在上面的示例中,跳过处理空值,但必须将其包含在实际工作中)

List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
List<Order> sortedList =
    clients.OrderBy(o => o.ClientOrder)
           .ThenBy(o => o.ClientName)
           .ToList();
clients.Sort(new Comparison<Client>(
    (client1, client2) =>
    {
        // compare dates
        int result = client1.OrderDate.CompareTo(client2.OrderDate);
        // if dates are equal (result = 0)
        if(result == 0)
            // return the comparison of client names
            return client1.ClientName.CompareTo(client2.ClientName);
        else
            // otherwise return dates comparison
            return result;
    })
);