How to copy an object by value, not by reference
- by Blankman
I want to make a copy of an object, then after some logic, re-assign the original object the value of the copy.
example:
User userCopy = //make a copy
foreach(...)
{
user.Age = 1;
user.ID = -1;
UserDao.Update(user)
user = userCopy;
}
I don't want a copy by reference, it has to be a copy by value.
The above is just a sample, not how I really want to use it but I need to learn how to copy by value.