I have a list which I want to update using LINQ.
class Student
{
private string name;
private int marks;
public string Name { get; set;}
public int Marks { get; set; }
public Student(string name, int marks)
{
Name = name;
Marks = marks;
}
}
List<Student> myList = new List<Student>();
myList.Add(new Student("John", 10));
myList.Add(new Student("Tom", 20));
Now I want to update the list using LINQ such that only marks of John gets updated. I am using the following syntax:
myList.Where(w => w.Name == "Tom").Select(w=> { w.Marks = 35; return w});
But this doesnt update data in myList. Can someone tell me where am I going wrong.