本文概述
- LINQ OrderBy运算符的语法
- LINQ OrderBy运算符示例
LINQ OrderBy运算符的语法 LINQ中LINQ OrderBy运算符的语法以升序对列表/集合值进行排序。
C#代码
var studentname = Objstudent.OrderBy(x =>
x.Name);
LINQ OrderBy运算符示例
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1{class Program{static void Main(string[] args){List<
Student>
Objstudent = new List<
Student>
(){new Student() { Name = "Suresh Dasari", Gender = "Male", Subjects = new List<
string>
{ "Mathematics", "Physics" } }, new Student() { Name = "Rohini Alavala", Gender = "Female", Subjects = new List<
string>
{ "Entomology", "Botany" } }, new Student() { Name = "Praveen Kumar", Gender = "Male", Subjects = new List<
string>
{ "Computers", "Operating System", "Java" } }, new Student() { Name = "Sateesh Chandra", Gender = "Male", Subjects = new List<
string>
{ "English", "Social Studies", "Chemistry" } }, new Student() { Name = "Madhav Sai", Gender = "Male", Subjects = new List<
string>
{ "Accounting", "Charted" } }};
var studentname = Objstudent.OrderBy(x =>
x.Name);
foreach (var student in student name){Console.WriteLine(student.Name);
}Console.ReadLine();
}}class Student{public string Name { get;
set;
}public string Gender { get;
set;
}public List<
string>
Subjects { get;
set;
}}}
在上面的示例中, 我们声明了一个变量类型为var的学生姓名, 并在学生集合中使用了order by子句, 并提到了名为” 名称” 的列以基于” 名称” 的升序对值列表进行排序。
输出
文章图片
推荐阅读
- LINQ OrderBy降序运算符
- LINQ排序运算符(Order By, then By, Reverse)
- LINQ Aggregate()函数
- LINQ Count()函数
- LINQ sum()函数
- LINQ Max()函数
- LINQ Min()函数
- LINQ语法详解
- LINQ Lambda表达式语法