When we want to modify some value in one object we may use two different methods, just want to know which one is better or there is no big different between them.
-
1.
void SomeMethod()
{
UserInfo newUser = New UserInfo();
ModifyUserInfo(newUser);
//Modify UserInfo after calling void method GetUserInfo
}
void ModifyUserInfo(UseerInfo userInfo)
{
userInfo.UserName = "User Name";
.....
}
-
2.
void SomeMethod()
{
UserInfo newUser = New UserInfo();
//Assign new userinfo explicitly
newUser = GetUserInfo(newUser);
}
UserInfo ModifyUserInfo(UseerInfo userInfo)
{
userInfo.UserName = "User Name";
.....
return userInfo;
}
I would prefer a third:
Basically this lets
GetUserInfohandle all of the details of building upUserInfo, and your calling code does not have to worry about any of the details other than the object it is getting back.