In below code why filteredStudentNames
holds only 2 elements.
As per my understanding, it is reference type so when I update the studentList
object with one more item that results should also be part of filteredStudentNames
.
In the case of studentNames
object, I am getting the updated record also.
So why not in the case of filteredStudentnames
?
static void Main(string[] args)
{
IList<Student> studentList = new List<Student>() {
new Student() { StudentID = 1, StudentName = "John", age = 18 } ,
new Student() { StudentID = 2, StudentName = "Steve", age = 21 } ,
new Student() { StudentID = 3, StudentName = "Bill", age = 18 } ,
new Student() { StudentID = 4, StudentName = "Ram" , age = 20 } ,
new Student() { StudentID = 5, StudentName = "Ron" , age = 21 }
};
var filteredStudentNames = from s in studentList
where s.age > 20
select s;
var studentNames = from s in studentList
select s;
IList<Student> stud = studentList;
studentList.Add(new Student { StudentID = 27, StudentName = "Test" });