31
1
//example by TutorialsTeacher
2
using System;
3
using System.Linq;
4
using System.Collections.Generic;
5
6
public class Program
7
{
8
public static void Main()
9
{
10
IList<Student> studentList = new List<Student>() {
11
new Student() { StudentID = 1, StudentName = "John", age = 18 } ,
12
new Student() { StudentID = 2, StudentName = "Steve", age = 21 } ,
13
new Student() { StudentID = 3, StudentName = "Bill", age = 18 } ,
14
new Student() { StudentID = 4, StudentName = "Ram" , age = 20 } ,
15
new Student() { StudentID = 5, StudentName = "Ron" , age = 21 }
16
};
17
18
var students = from s in studentList
19
select new { Id = s.StudentID, Name = s.StudentName };
20
21
foreach(var stud in students)
22
Console.WriteLine(stud.Id + "-" + stud.Name);
23
}
24
}
25
public class Student
26
{
27
public int StudentID { get; set; }
28
public string StudentName { get; set; }
29
public int age { get; set; }
30
}
31
Cached Result
1 | 2 | 3
-------------
4 | 5 | 6
-------------
7 | 8 | 9
-------------
4 | 5 | 6
-------------
7 | 8 | 9