I am trying to develop a Windows 8 App in Visual Studio Express 2012 for Windows 8 using C#/XAML, and I am facing some problems while doing so.
I am from a Java background and have little knowledge of C#. I am trying to translate Java Enum to C#.
I stumbled upon Jon Skeet’s Article which fits in my exact requirement. But from the comments and answers of this question, I realised that it’s a proposed idea. My bad! 🙂
However, the closest translation I found after the above article is this one:
https://stackoverflow.com/a/4778347/1127443
But even with the above implementation, VS cannot find the getCustomAttribute() method in Attribute.
How can I implement the idea of Java Enums in C# where common fields and abstract functions can be defined? Basically, I want to bring back the idea of enums as a set of allowed instances of a particular class with specific implementations.
Here is what I would do to be as close to your code as possible:
Don´t use enum, but create a static class with some constant fields:
You can use it just like any other method:
Or use it in a parameter just like an enum:
You can pass any
Func<int, int, int>as a parameter, not only ArithmeticOperation´s property.