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.
dkilbyAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.