D
David R
I'd like to create a list of enumerated types, and then loop through each of
those types to perform a standard operation on each. The following sample
gives an idea of what I'd like to accomplish, but it doesn't work and I don't
know the correct way to do this. Is this possible? If so, what should each
of my foreach loops look like? Thanks.
private enum Colors { Red, Yellow, Blue, Green };
private enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
private enum Months { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
Dec };
private Type[] enumTypes = { typeof(Colors), typeof(Days), typeof(Months) };
static void Main(string[] args)
{
// Go through each of the enumerated types
foreach (Type currentType in enumTypes)
{
Console.WriteLine( currentType.ToString() );
// Display the names of each of the members
foreach (string s in
((System.Enum)currentType).GetNames(typeof(currentType)))
{
Console.WriteLine(s);
}
}
}
those types to perform a standard operation on each. The following sample
gives an idea of what I'd like to accomplish, but it doesn't work and I don't
know the correct way to do this. Is this possible? If so, what should each
of my foreach loops look like? Thanks.
private enum Colors { Red, Yellow, Blue, Green };
private enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
private enum Months { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
Dec };
private Type[] enumTypes = { typeof(Colors), typeof(Days), typeof(Months) };
static void Main(string[] args)
{
// Go through each of the enumerated types
foreach (Type currentType in enumTypes)
{
Console.WriteLine( currentType.ToString() );
// Display the names of each of the members
foreach (string s in
((System.Enum)currentType).GetNames(typeof(currentType)))
{
Console.WriteLine(s);
}
}
}