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. The MSDN documentation for System.ValueType uses
the term "structure" as well.
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:
public enum AnEnum { A, B }
class Program
{
static void Test<T>(T value)
where T : struct
{
Console.WriteLine("Testing: " + value.ToString());
}
static void Main(string[] args)
{
Test<int>(5);
Test<AnEnum>(AnEnum.B);
Console.WriteLine("Done");
Console.ReadLine();
}
}
Output:
Testing: 5
Testing: B
Done
So, it seems that even the C# compiler will treat types derived from Enum as
structs. The C# "enum" keyword was really the only thing preventing me from
thinking that "structure" was the same as "struct". But now it's obvious to
me that the "enum" keyword simply replaces "struct", providing a more specific
way (and only way) of declaring enums in the C# language.
I believe now that "enum" (C#) is a more-derived concept, but still describes
a "struct". Since all "structs" are "value-types", including "enums", and
since the term "structure" refers to all ValueTypes as well [MSDN docs], I
must conclude that the term "structure" is equal to "struct" and that "enum"
can be referred to as "enum", "struct", or "structure", in the same way that
"XmlDocument" may be referred to as "object". The term "structure", I think
of as a language-agnostic way to describe a value-type. The term "struct",
when used outside of a C# context can be used interchangeably with
"structure", since they mean the same thing. In a context that deals with the
C# compiler directly, I'll try to refrain from using "structure" as it
obviously has no place within the C# language itself. When speaking of the
VB.NET compiler it may be used freely because it apparently means the same
thing as the C# "struct" keyword.
The glossary needs to be updated ;)
I don't think that in the context of this thread the term "struct" was misused
by anyone, including Mark, who claims to have been the first to misuse the
term. Anytime "struct" or "structure" was used, IIRC, value-type was "meant",
and that seems now to have been just fine.
--
Dave Sexton