I have a class in C#:
public static class Constants
{
public static class Animals
{
public const string theDog = "dog";
public const string theCat = "cat";
}
}
And I want to loop through the "assignments" of that class (not the properties). And I want to get the values without having to explicitly specify the property. I'm trying to do this because I have a class of a a lot of constants and I want to add them to a list.
So, my desired output / code would look something like this:
foreach (string animal in Constants.Animals)
{
Console.WriteLine(animal)
}
Output:
dog
cat
I have tried reflection, but that only gives me the property.