Defining an enum the hard way RRS feed

  • Question

  • I'm still porting C# code to .NET language X. The question now is, how to define an enumeration type.

    Page 25 of standard ECMA 335 (4th Edition) indicates that the CTS supports enumeration types (partition I, section 8.5.2).

    But does the CLS require .NET languages to provide an equivalent for C#'s enum keyword? If so, I'll dig deeper into the spec for language X.

    If not, the followup question would be: Is there an alternative syntax in C# for defining an enumeration type? Maybe the alternative syntax would be easier to port.

    Take this example:

        public enum CommandType  

    I'm guessing that this is syntactic sugar for (somehow) inheriting from System.Enum. Is that a correct guess, and is there an example you could point out, which shows how to inherit from System.Enum without the sugar?

    This does not work:

        public class CommandTypes : System.Enum  
            // ...  
    It yields the error: cannot derive from special class 'System.Enum'


    Wednesday, February 4, 2009 3:52 PM


  • It turns out that at least one vendor's implementation of language X does provide an enum keyword, as a language extension. So my immediate question is answered.

    If you reply with anything else of interest about this topic as it relates to C# or the CLR, I'll mark that as the answer.
    • Marked as answer by Matt Fisher Wednesday, February 4, 2009 5:47 PM
    Wednesday, February 4, 2009 5:47 PM