How to update value in a List using LINQ

后端 未结 9 974
天命终不由人
天命终不由人 2020-12-31 14:45

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         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 15:45

    Above can be achieved by just assign the value back to the collection

    myList = myList
            .Where(w => w.Name == "Tom")
            .Select(w=> { w.Marks = 35; return w})
            .ToList();
    

提交回复
热议问题