Aryeh Holzer <(E-Mail Removed)> wrote:
> I'm sure you're right, although the documentation is very confusing,
> then. The entries on "Structs", for instance, says "All value types in
> C# inherently derive from System.ValueType, which inherits from
> System.Object. Value types can be converted to reference types by the
> compiler in a process known as boxing." - which kind of implies that
> the ValueType is not natively a reference, but must be converted into
> one by boxing it.
>
> Thanks for the pointer (ow) to the feedback center, I think I'll head
> there now.
Yes, the value type system *is* very confusing, unfortunately. The ECMA
CLI spec is the clearest here:
<quote>
Not all types defined by a class definition are object types (see
clause 8.2.3); in particular, value types are not object types but they
are defined using a class definition. A class definition for a value
type defines both the (unboxed) value type and the associated boxed
type (see clause 8.2.4). The members of the class definition define the
representation of both: 1. When a non-static method (i.e. an instance
or virtual method) is called on the value type its this pointer is a
managed reference to the instance, whereas when the method is called on
the associated boxed type the this pointer is an object reference.
Instance methods on value types receive a this pointer that is a
managed pointer to the unboxed type whereas virtual methods (including
those on interfaces implemented by the value type) receive an instance
of the boxed type.
1. Value types do not support interface contracts, but their associated
boxed types do.
2. A value type does not inherit; rather the base type specified in the
class definition defines the base type of the boxed type.
</quote>
and
<quote>
Value Types, in their unboxed form, do not inherit from any type. Boxed
value types shall inherit directly from System.ValueType unless they
are enumerations, in which case they shall inherit from System.Enum.
Boxed value types shall be sealed.
</quote>
Still not as clear as it might be - and not helped by typeof(int), for
example, claiming to be a value type but also claiming to derive from
ValueType, etc...
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too