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.