Items in lists by string

Top  Previous  Next

Here are 2 different ways of doing the same thing, i.e. getting a HoleFeature by its text name:

 

 

       // Get it directly and hope it is there

       HoleFeature Hole7 = SpallaDef.Features.HoleFeatures["Hole7"] ;

 

or

 

       // Look for it, Hole7 remains null if not found

       HoleFeature Hole7 = null;

       foreach (HoleFeature ThisHole in SpallaDef.Features.HoleFeatures)

       {

           if (ThisHole.Name == "Hole7")

           {

               Hole7 = ThisHole;

               break;

           }

       }

       if (Hole7 == null)

       {

           return;

       }

 

 

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)