Question

Am I correct in believing that any object that doesn't inherit from System.ValueType must therefore by definition be a reference type?

I've been unable to find any conclusive documentation to backup this notion.

Was it helpful?

Solution

Check if this helps.

enter image description here

OTHER TIPS

If you read closely the Remarks you'll see that

Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocated. Both reference and value types are derived from the ultimate base class Object. In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object.

C# compiler does a wonderful job making you think that value types like int long has methods

If you were on QI and Stephen Fry was doing his normal thing of being what an impressionable idiot thinks a smart person is like, then he'd have reacted to "any object that doesn't inherit from System.ValueType must therefore by definition be a reference type" with a klaxon and a flashing screen saying "all objects are value types or reference types".

He'd then go on to point out that originally in computer science, object meant any entity that could be manipulated by a computer, and therefore includes pointers, which .NET has, even though they are don't fit the later definition of object (the word later said with a certain tone of condescension) that refers to objects that are encapsulated with their methods, and therefore you're wrong.

Alan Davies would point out that everyone knew what you meant, but it would be too late, your statement would have served only to fuel Fry's warm glow of smugness, especially since technology comes perhaps second only to Oscar Wilde in the ranks of things he likes to think he can talk intelligently about (and perhaps second to none in the ranks of things he knows nothing about, now I think of it, there's no way he'd manage to say the above and not get it wrong in some way).

In other words yes, you are completely right :)

(Apologies to those who haven't seen much British television, and therefore don't have a clue what any of that meant).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top