37
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 = 13} ,
13
new Student() { StudentID = 2, StudentName = "Moin", Age = 21 } ,
14
new Student() { StudentID = 3, StudentName = "Bill", Age = 18 } ,
15
new Student() { StudentID = 4, StudentName = "Ram" , Age = 20} ,
16
new Student() { StudentID = 5, StudentName = "Ron" , Age = 15 }
17
};
18
19
// LINQ Query Syntax to find out teenager students
20
var teenAgerStudent = from s in studentList
21
where s.Age > 12 && s.Age < 20
22
select s;
23
Console.WriteLine("Teen age Students:");
24
25
foreach(Student std in teenAgerStudent){
26
Console.WriteLine(std.StudentName);
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
37
}
Cached Result
A kék autó nyert!
A piros autó a 55. mezőn állt.
Célfotó:
------------------------------------------------------*-----
-----------------------------------------------------------+
A piros autó a 55. mezőn állt.
Célfotó:
------------------------------------------------------*-----
-----------------------------------------------------------+