Instead of using a Switch statement as shown in the code below, is there an alternative way to check if foo.Type
is a match to any of the constants in the Parent.Child
class?
The intended goal is to loop through all of the constant values to see if foo.Type
is a match, rather than having to specify each constant as a case
.
Parent Class:
public class Parent
{
public static class Child
{
public const string JOHN = "John";
public const string MARY = "Mary";
public const string JANE = "Jane";
}
}
Code:
switch (foo.Type)
{
case Parent.Child.JOHN:
case Parent.Child.MARY:
case Parent.Child.JANE:
// Do Something
break;
}