Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

Passing User data around: objects vs List<> vs your choice?

Is it a good idea to assign values from the User Interface to an object, and then pass the object on to where it is required (or store it somewhere), or would adding it to a List<> be better, since I assume it would not be as "heavy" to pass around? Of cause it depends on the needs and requirements as to which approach to use, but in which types of scenarios  (user data) would you use objects, and in which would you use List<>, or other? Why?
0
userTester
Asked:
userTester
  • 4
  • 3
4 Solutions
 
CodeCruiserCommented:
Objects can have any number of properties of any type where as a list can have only values of same type. Objects that you create yourself only have the properties and methods that you define where as list classes have a lot of predefined properties, methods, events etc and may be inheriting from 10 other classes or implementing 10 other interfaces. So if efficiency is the goal then object would be the choice. It is a common practice to use DTO objects to transfer information between different parts of an application.
0
 
käµfm³d 👽Commented:
Why would a List<> be any less heavy than another object? Only references are passed around when dealing with objects (which a List<> is, btw. Everything in .NET is an object!!).
0
 
userTesterAuthor Commented:
Thanks to both comments.

The reason I say a list would be less-heavy is because lists can be created to only contain the required data that is needed for a specific purpose, while and object might also have data that is not needed in certain circumstances, so the extra data is passed around despite not being needed in all circumstances.

Please correct me if I have this incorrect:
If I use List<string> then the string data is all that I am passing around, but if I used List<MyObject>, then I would be passing a list of custom objects around.

Do you have a simple DTO example I can quickly run through?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CodeCruiserCommented:
DTO would involve creating your own class and passing it around.

It also depends on your requirements though. Do you only need to pass strings around?
0
 
userTesterAuthor Commented:
I like the idea of custom objects, but yes, strings are the idea here. Are you suggesting using List<string> in this case?
0
 
CodeCruiserCommented:
We don't know what information you need to pass around. If it is employee information then it would make sense to use an employee class. If its a few (or more) strings then list of string would make sense.
0
 
userTesterAuthor Commented:
That's fine, just needed your take on the use of lists vs objects.
0
 
userTesterAuthor Commented:
Thanks for answering my questions, appreciate it.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now