C
C#4mo ago
Mark_P

✅ Can I put an extension method directly on an enum, not a value in the enum?

If I have an enum
public enum MyEnum{one, two, three}
public enum MyEnum{one, two, three}
can I put an extension method on it so I can use it like this
MyEnum.MyExtensionMethod()
MyEnum.MyExtensionMethod()
rather than
MyEnum.one.MyExtensionMethod()
MyEnum.one.MyExtensionMethod()
And I only want it on that specific enum, not all enums
5 Replies

Did you find this page helpful?