博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
List排序的两种简便方式
阅读量:2236 次
发布时间:2019-05-09

本文共 1581 字,大约阅读时间需要 5 分钟。

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 = "客户1", id = 0 }); listCustomer.Add(new Customer { name = "客户2", id = 1 }); listCustomer.Add(new Customer { name = "客户3", id = 5 }); listCustomer.Add(new Customer { name = "客户4", id = 3 }); listCustomer.Add(new Customer { name = "客户5", id = 4 }); listCustomer.Add(new Customer { name = "客户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; } }}

 

转载于:https://www.cnblogs.com/zeroone/p/4053241.html

你可能感兴趣的文章
利用栈实现DFS
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>
(PAT 1080) Graduate Admission (排序)
查看>>
Play on Words UVA - 10129 (欧拉路径)
查看>>
mininet+floodlight搭建sdn环境并创建简答topo
查看>>
【linux】nohup和&的作用
查看>>
Set、WeakSet、Map以及WeakMap结构基本知识点
查看>>
【NLP学习笔记】(一)Gensim基本使用方法
查看>>
【NLP学习笔记】(二)gensim使用之Topics and Transformations
查看>>
【深度学习】LSTM的架构及公式
查看>>
【python】re模块常用方法
查看>>
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 60. 不用加减乘除做加法
查看>>
Leetcode C++《热题 Hot 100-15》437.路径总和III
查看>>
Leetcode C++《热题 Hot 100-17》461.汉明距离
查看>>