Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update all properties in list using linq

I need to update all the properties in a list object using linq.

For ex.: I have an User List with (Name, Email, PhoneNo,...) as properties. I will get the Users List(List<Users>) from database which is filled with all properties except Email. I need to update all the Email property in the list after retrieving from database with some email in session.

How can i do it?

like image 318
Prasad Avatar asked Dec 17 '25 14:12

Prasad


1 Answers

You should be able to do it simply via ForEach..

users.ForEach(user => user.email = sessionEmail);

or for multiple properties..

users.ForEach(user => 
{
    user.email = sessionEmail;
    user.name = "Some Person";
    ...
});
like image 188
Quintin Robinson Avatar answered Dec 19 '25 06:12

Quintin Robinson