What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

List help

Status
Not open for further replies.

remark

New Member
Joined
Nov 13, 2014
Messages
58
Reaction score
0
Been many years since i programmed for real

and i seem to remember there was something with having some nested lists or something

so if i have a dataset

workstationid(packid, craftid, packnamepackid, craftid, packname,packid2, craftid2, packname2), workstationid(packid, craftid, packname,packid2, craftid2, packname2) etc.

and you'd call it by like dataset[1],craftid[2] to get the craftid2 of the number 1 set.

but i cant for the life of me figure out how to do something similar in c#

does anyone have a simple clean example of doing this?
 
To access an object in a list, do something like:

Code:
var myList= new List<Workstationid>();
var craftId= myList[0].craftId2;

This is assuming that what you want is the "craftId2" property in the first object of your list. The problem with this approach is that if the list is empty it'll throw a null reference exception. Whenever you have a list of objects, and you want to retrieve one of those objects, there's usually two approaches that are better. If you will always want to retrieve your objects by a single property they have (like an Id number), then use a Dictionary<,> instead of a List<>. On the other hand, if you want to "find an object who's X property has a value of Y", you can use Linq queries, which are clean and easy to use once you understand them.
 
Last edited:
Status
Not open for further replies.
Back
Top