I'm trying to make an extension method that can apply to all/any enum, that returns the string constants of the enum as a list of strings.
this did not work.
static class EnumEx
{
public static List<string> ToList(this System.Enum e)
{
return System.Enum.GetNames (e.GetType()).ToList();
}
}
I'm calling it like:
public enum TestEnum { HELLO, WORLD };
foreach(string e in TestEnum.ToList())
Console.Writeline(e);
UPDATE:
TestEnum instance = new TestEnum();
foreach(string e in instance.ToList())
Console.Writeline(e);
and get the errors:
Type string[]' does not contain a member
ToList' and the best extension method overload EnumEx.ToList(this System.Enum)' has some invalid arguments
Extension method instance type
string[]' cannot be converted to `System.Enum'