I want to declare several constant objects that each have two subobjects, and I’d like to store these in an enum for organizational purposes.
Is it possible to do something like this in C#?
enum Car
{
carA = { 'ford', 'red' }
carB = { 'bmw', 'black' }
carC = { 'toyota', 'white' }
}
No, the C# language does not allow for that.
You can create a
You would add entries to it like
Note though that if you are mixing the concept of “ford” and “red”, you may want to consider creating an object to represent that thing, e.g.
Then, your
Dictionaryobject would look like