I tried to simplify my problem with this example:
List<User> userList = new List<User>()
{
new User {IdUser = 1, Login = "Frank" },
new User {IdUser = 2, Login = "Pat" },
new User {IdUser = 3, Login = "Max" },
new User {IdUser = 4, Login = "Paul" },
new User {IdUser = 5, Login = "John" }
};
User newUser = new User()
{
IdUser = 3,
Login = "Chris"
};
var userToUpdate = userList.FirstOrDefault(r => r.IdUser == 3);
userToUpdate = newUser;
why userList
does not contain the value Login = "Chris"
by the end of this program? How is it possible to update an item within a list?
PS1: I don't want to update the Login
value, I want to update the User Object
PS2: It says in this link that FirstOrDefault selects an item in a collection, but does not "detatch" or "clone" it. I.e. it is the same instance. So if you modify a property you modify the original instance.
I am confused!