As a follow on from this question.
How can I call a function and pass in an Enum?
For example I have the following code:
enum e1 { //... } public void test() { myFunc( e1 ); } public void myFunc( Enum e ) { var names = Enum.GetNames(e.GetType()); foreach (var name in names) { // do something! } }
Although when I do this I am getting the ‘e1’ is a ‘type’ but is used like a ‘variable’ Error message. Any ideas to help?
I am trying to keep the function generic to work on any Enum not just a specific type? Is this even possible?… How about using a generic function? would this work?
You can use a generic function:
and call like:
(EDIT)
The compiler complains if you try to constraint
TtoEnumorenum.So, to ensure type safety, you can change your function to: