43
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 thenByResult = studentList.OrderBy(s => s.StudentName).ThenBy(s => s.Age);
20
21
var thenByDescResult = studentList.OrderBy(s => s.StudentName).ThenByDescending(s => s.Age);
22
23
Console.WriteLine("ThenBy:");
24
25
foreach (var std in thenByResult)
26
Console.WriteLine("Name: {0}, Age:{1}", std.StudentName, std.Age);
27
28
Console.WriteLine("ThenByDescending:");
29
30
foreach (var std in thenByDescResult)
31
Console.WriteLine("Name: {0}, Age:{1}", std.StudentName, std.Age);
32
33
}
34
35
}
36
37
public class Student{
38
39
public int StudentID { get; set; }
40
public string StudentName { get; set; }
41
public int Age { get; set; }
42
43
}
Cached Result
Run-time exception (line 15): 'object' does not contain a definition for 'GetEnumerator'
Stack Trace:
[Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'GetEnumerator']
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Program.Main() :line 15
Stack Trace:
[Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'GetEnumerator']
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Program.Main() :line 15