Iterate over enum?
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-04-13T19:56:03Z
Indexed on
2010/04/13
20:03 UTC
Read the original article
Hit count: 474
I'm trying to iterate over an enum, and call a method using each of its values as a parameter. There has to be a better way to do it than what I have now:
foreach (string gameObjectType in Enum.GetNames(typeof(GameObjectType)))
{
GameObjectType kind = (GameObjectType) Enum.Parse(typeof (GameObjectType), gameObjectType);
IDictionary<string, string> gameObjectData = PersistentUtils.LoadGameObject(kind, persistentState);
}
//...
public static IDictionary<string, string> LoadGameObject(GameObjectType gameObjectType, IPersistentState persistentState) { /* ... */ }
Getting the enum names as strings, then parsing them back to enums, feels hideous.
© Stack Overflow or respective owner