38
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, StandardID = 1 } ,
13
new Student() { StudentID = 2, StudentName = "Steve", Age = 21, StandardID = 1 } ,
14
new Student() { StudentID = 3, StudentName = "Bill", Age = 18, StandardID = 2 } ,
15
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20, StandardID = 2 } ,
16
new Student() { StudentID = 5, StudentName = "Ron" , Age = 21 }
17
};
18
19
var studentNames = studentList.Where(s => s.Age > 18)
20
.Select(s => s)
21
.Where(st => st.StandardID > 0)
22
.Select(s => s.StudentName);
23
24
25
foreach(var name in studentNames){
26
Console.WriteLine(name);
27
}
28
}
29
}
30
31
public class Student{
32
33
public int StudentID { get; set; }
34
public string StudentName { get; set; }
35
public int Age { get; set; }
36
public int StandardID { get; set; }
37
}
38
Cached Result
Steve
Ram
Ram