47
1
using System;
2
using System.Linq;
3
using System.Collections.Generic;
4
5
6
public class Program
7
{
8
public static void Main()
9
{
10
// Student collection
11
IList<Student> studentList = new List<Student>() {
12
new Student() { StudentID = 1, StudentName = "John", Age = 18 } ,
13
new Student() { StudentID = 2, StudentName = "Steve", Age = 15 } ,
14
new Student() { StudentID = 3, StudentName = "Bill", Age = 25 } ,
15
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20 } ,
16
new Student() { StudentID = 5, StudentName = "Ron" , Age = 19 }
17
};
18
19
var orderByResult = from s in studentList
20
orderby s.StudentName //Sorts the studentList collection in ascending order
21
select s;
22
23
var orderByDescendingResult = from s in studentList //Sorts the studentList collection in descending order
24
orderby s.StudentName descending
Cached Result
8