I have a list which I want to update using LINQ.
class Student
{
private string name;
private int marks;
public string Name { get; set;}
pub
This is kind of clunky, but works, and doesn't depend on being passed a reference. It creates a new list based on the old.
var myList=myList.Select(l=>new Student {
l.Name,
Marks=l.Name=="Tom"?35:l.Marks}).ToList();
Or more silly:
var myList=myList.Where(l=>l.Name!="Tom").Union(
myList.Where(l=>l.Name=="Tom").Select(l=>new Student {
l.Name,
Marks=35})).ToList();