亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

c#對(duì)list排序示例

 更新時(shí)間:2014年01月06日 11:22:27   作者:  
本文主要介紹了c#對(duì)List成員排序的示例,大家參考使用吧

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ListSort
{
class Program
{
static void Main(string[] args)
{
List listCustomer = new List();
listCustomer.Add(new Customer { name = "客戶(hù)1", id = 0 });
listCustomer.Add(new Customer { name = "客戶(hù)2", id = 1 });
listCustomer.Add(new Customer { name = "客戶(hù)3", id = 5 });
listCustomer.Add(new Customer { name = "客戶(hù)4", id = 3 });
listCustomer.Add(new Customer { name = "客戶(hù)5", id = 4 });
listCustomer.Add(new Customer { name = "客戶(hù)6", id = 5 });
///升序
List listCustomer1 = listCustomer.OrderBy(s => s.id).ToList();
//降序
List listCustomer2 = listCustomer.OrderByDescending(s => s.id).ToList();
//Linq排序方式
List listCustomer3 = (from c in listCustomer
orderby c.id descending //ascending
select c).ToList();
Console.WriteLine("List.OrderBy方法升序排序");
foreach (Customer customer in listCustomer1)
{
Console.WriteLine(customer.name);
}
Console.WriteLine("List.OrderByDescending方法降序排序");
foreach (Customer customer in listCustomer2)
{
Console.WriteLine(customer.name);
}
Console.WriteLine("Linq方法降序排序");
foreach (Customer customer in listCustomer3)
{
Console.WriteLine(customer.name);
}
Console.ReadKey();
}
}
class Customer
{
public int id { get; set; }
public string name { get; set; }
}
}

相關(guān)文章

最新評(píng)論