Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-06-14
8
428 Views
Last Modified: 2013-06-15
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
Comment
Question by:userTester
  • 4
  • 3
8 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 375 total points
ID: 39249906
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
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 125 total points
ID: 39249985
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
 

Author Comment

by:userTester
ID: 39250643
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 375 total points
ID: 39250648
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
 

Author Comment

by:userTester
ID: 39250662
I like the idea of custom objects, but yes, strings are the idea here. Are you suggesting using List<string> in this case?
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 375 total points
ID: 39250680
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
 

Author Comment

by:userTester
ID: 39250700
That's fine, just needed your take on the use of lists vs objects.
0
 

Author Closing Comment

by:userTester
ID: 39250722
Thanks for answering my questions, appreciate it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question