Link to home
Create AccountLog in
Avatar of l2Bravo
l2BravoFlag for United States of America

asked on

List<> and indexing

I have a program I need to develop that uses multiple objects in sets of 12.  The objects are cylinder, scale, datatable, test, and possibly one or two others.  Cylinder1 needs to be paired with scale1 and so on up to 12 and the same goes for the other objects.  Generally, when I work with these objects, I need to loop through all of them and assign a value from one of them, say scale1.value, to another, say cylinder1.weight based on certain conditions.  

My assumption is that I can use the List<T> class to group all cylinder objects in one list and the same applies to the other objects I'm working with.  If I create the Lists in the correct order, an indexer will allow me to loop through the objects and get the correspondence correct, like this:

for(int listIndex=0; listIndex < cylinderList.Count; listIndex++)


Is this an effective (and safe) way to accomplish what I need to do?  Is there a better way?

Avatar of plusone3055
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account