Best way to prepare C # objects in separate methods

Which is better to use for object preparation logic:

a) with a return value

List<Users> users = LoadUsers();
users = PrepareUsers(users);

      

b) or with the void type

List<Users> users = LoadUsers();
PrepareUsers(users)

      

+3


source to share


2 answers


Are you setting properties of existing objects User

or creating new ones?

If you are just changing existing objects, then there is no reason why you want them back, this is overkill. Worse, it is misleading - the client will think that their objects are intact and that you are creating new objects when in fact they are not.



If you create new ones, then you obviously need to return them.

+4


source


Alternative b. since you are working with the same user objects, there is no reason to reassign the variable.



0


source







All Articles