Re: Type alias in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Dustin,

I think that referring to this as "one small paragraph" is quite an
understatement. I mean, if you can't trust the definition in the
*glossary*, what can you trust?

Good point :)

I trust the fact that every document in the MSDN library for all FCL
ValueTypes (of course, I haven't verified ALL) explicitly state each
as "Structure" in their titles.

Except that all FCL enumerations (which are also ValueTypes) list "Enumeration" in their titles. Since enumerations are ValueTypes, that statement isn't really correct. So, why does your logic for the presence of the keyword "Structure" not apply to the presence of the keyword "Enumeration" as well? It seems like you are trying to use this title keyword to prove your point but it really seems to prove mine -- that enumerations are not "structures".

Interestingly enough, I searched the C# glossary, "struct" keyword
definition and some programming guidance documentation (all C#) but
none contained the term "structure" in any related way. (It's used to
describe a "data structure" though).

In VB.NET, as you mentioned in another post in this thread, the term
"Structure" appears to mean value-type. It's used for constraining
generic arguments. You have the choice of "Class", "Structure" or
neither keyword in VB.NET. In C#, "class", "struct" or neither
keyword may be used to constrain generic arguments after the "where"
statement.

If you use the C# keyword "struct" to constrain a generic argument you
can successfully pass in an enum value:

That indeed is a good point but that constraint is really only ensuring that a type argument will descend from System.ValueType -- not that it is a C# struct. So, its use on enumerations could simply be considered a side effect.

I just can't understand how an enum can be considered a structure when it only shares one feature of structures: stack allocation. Other features such as interface implementation and method declaration are not supported on enums. And, using your own argument, the MSDN documentation never refers to an enumeration as a "structure". Therefore, I have to conclude that enums *are* different from structs. They are different kind of entity that are also allocated on the stack. Of course, I'd really *like* to see Microsoft make enumerations more like standard structures. It seems to me that it would be extremely useful to have instances methods and interface support for enum types.

Best Regards,
Dustin Campbell
Developer Express Inc.


.



Relevant Pages

  • Re: Type alias in C#
    ... I mean, if you can't trust the definition in the *glossary*, ... The MSDN documentation for System.ValueType uses ... Interestingly enough, I searched the C# glossary, "struct" keyword definition ... public enum AnEnum ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: To const or to enum?
    ... > out on the side of using enumerations over static constants. ... be losing any sleep over an enum. ... Each node type is assigned an integral constant ...
    (comp.lang.cpp)
  • Re: enum is poorly defined
    ... * The C++ enum keyword has problems, mostly for historical reasons, ... * Further, in supporting a range, rather than the individual keywords, ...
    (comp.lang.cpp)
  • Re: Jython inherit from Java class
    ... Compiling .java to .class... ... 'assert' is a keyword, and may not be used as an identifier ... release 1.5, 'enum' is a keyword, and may not be used as an identifier ...
    (comp.lang.python)
  • Re: Compiler resolves to wrong overloaded constructor or method
    ... Adding an implicit value removes one possible value from all ... > if, as I suggested, it's a language keyword. ... Because if it is a member of a given enum, ... each other keyword has a practical common usage. ...
    (microsoft.public.dotnet.languages.csharp)