Avatar of l2Bravo
l2Bravo
Flag 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++)
{

      if(cylinderList[listIndex].Activated)
     {
          cylinderList[listIndex].Weight=scaleList[listIndex].Value;
     }
}

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

Thanks.
C#

Avatar of undefined
Last Comment
plusone3055

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
plusone3055

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes