I'm new with enums and read it would be good to define enums outside of classes in the namespace.
namespace MyNamespace
{
public static enum Index
{
First = 0,
Last = 1,
}
public class MainPage
{
private MyClass[] myClasses = new MyClass[2];
public MainPage()
{
myClasses[Index.First] = new MyClass();
myClasses[Index.Last] = new MyClass();
}
}
public class MyClass{}
}
What I'm doing wrong?
Edit:
Code would work by this way:
public MainPage()
{
myClasses[(int)Index.First] = new MyClass();
myClasses[(int)Index.Last] = new MyClass();
}
To better understand what I want, here's my "Enumeration" based on my new knowledge:
namespace OnScreenKeyboard.Enumerations
{
namespace Key
{
public static class Keys
{
public const int Left = 0;
public const int Right = 1;
public const int Shift = 20;
public const int Backspace = 29;
public const int Numbers = 30;
public const int Country = 31;
public const int Space = 35;
public const int Enter = 39;
}
}
}
Where I can do this:
using OnScreenKeyboard.Enumerations.Key;
namespace OnScreenKeyboard
{
public MainPage()
{
InitializeComponent();
if (keyNumber == keys[Keys.Shift])
{
// Switch to Upper-Case Letters
}
}
}
I really would like to use enumerations, but if I must always write this ugly (int) in the Code, I prefer better constants.