Declaring and creating an object then adding to collection VS Adding object to collection using new
Posted
by ZeeMan
on Stack Overflow
See other posts from Stack Overflow
or by ZeeMan
Published on 2010-03-27T00:03:22Z
Indexed on
2010/03/27
0:13 UTC
Read the original article
Hit count: 207
c#
Ok so the title may have been confusing so i have posted 2 code snippets to illustrate what i mean.
NOTE: allUsers is just a collection.
RegularUser regUser = new RegularUser(userName, password, name, emailAddress);
allUsers.Add(regUser);
VS
allUsers.Add(new RegularUser(userName, password, name, emailAddress));
- Which snippet A or B is better and why?
- What are the advantages or disadvantages?
- The example i wrote was C# but does the language (C#, Java etc) make a difference?
© Stack Overflow or respective owner