As a whole I love C# but sometimes I find some quirk that I just don’t understand. I’m sure there is a reasonable explanation of why it works the way it does but I don’t know what it is.
I was building a Gtk.TreeView last night and setup an enum for each column in the TreeView. No big deal, right? The enum looks something like this:
enum1 = 0,
Then, to build the column I do something like this:
TreeViewColumn col = new TreeViewColumn ();
CellRenderer NameRenderer = new CellRendererText ();
col.PackStart (NameRenderer, true);
col.AddAttribute (NameRenderer, "text", (int)Fields.Keyword);
Notice on that last line that I have to cast the enum member to an int, even though the type of the enum is int, you still have to cast its value.
You can specify the base type of an enumerator, but it defaults to an int. You could do this (and I tried) but it doesn’t change anything:
enum Fields : int
enum1 = 0,
It would be nice to not need to cast the value of the enum, especially given the ability to explicitly set the type of the enum. I don’t know the internals of how the compiler works nor have I read the CLR specification. It’s just annoying to to tell an enum that it’s an int, only have to remind it of that fact every time you use it.