Huomautus
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää kirjautua sisään tai vaihtaa hakemistoa.
Tämän sivun käyttö edellyttää valtuutusta. Voit yrittää vaihtaa hakemistoa.
Why can't you enumerate Enums? You'd think you could, given the name!
What would it look like?
enum X { A, B, C, D }
foreach( X x in X ) { ... }
Okay, that won't fly because X is a type not an instance.
How about: foreach( X x in X.GetValues() )
Now, that would be possible, since you'd just be calling a static method that returns an enumable instance.
Why haven't we added this super-marvelous method to Enum's? Dunno. I suppose you could always write a static helper that enumerates enums using reflection. Maybe one day the perf of reflection will have improved enough to make you want to.
I can always hope.
Matt
Comments
- Anonymous
June 10, 2004
Der.. Apparently you can already to this using the Enum class. I guess I should actually read the manual first. Oh well. Like I ever know what I'm talking about anyway. - Anonymous
June 10, 2004
Whaich ennumerations do you want to enumerate when you enumerate enumerations