• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

C#.Net + populate object

i am trying to learn about objects, can i populate an object with an array of values, something simple like and list of ids and corrosponding names, i would like to get the list of names and id from a db and populate the object.
0
dkilby
Asked:
dkilby
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
yes u can, u need to declare your object to reflect the data u wish to populate from the database.
then u can use different methods to populate the object with the query result.
your question is quite generic, if u wish to get into details i'd suggest u post more practical requirements such as object structure, db type, query output etc.
0
 
ashraf882Commented:
Why not, just write a simple method to populate the object.
But why you have to do so?
0
 
joriszwaenepoelCommented:
In this case, I would suggest you create a class with 2 properties: "Id" and "Name".
For every row in your results from your database-query, you create a new instance of that class (= an object) and fill in the properties.

You can add all those objects to a generic List object, to make it easy to work with as a collection.

Hope this helps.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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