Since I learned that .NET doesn't have primitive types (I'm a reformed Java programmer) and that all data types inherit from Object, this one question has puzzled me.
What makes the determination that a given value type is set to value or reference type?
The answer I got in a book was along the lines of "if you use the new keyword then it's a reference type." I didn't find that to be a satisfying answer.
Some colleagues and I have been discussing it and we think that objects without constructor methods become value types and those with become reference types.
Are we on point? Or completely off the mark?
-
-
Completely off the mark. Basically, what you would think are primitives are value types (with the exception of structs, which are also value types) All others are reference types.
Check this page out.
It explains Value types in the CLR. -
There are a couple wierd concepts in this area

Value types must derive from either System.ValueType or System.Enum. The interesting thing is ValueType and Enum are reference types.
Also, all value types come with a default (parameterless) constructor to initialize a value type to "all bits zero":
int i = new int(); // legal C#
And if you declare your own ValueType, you cannot declare a default constructor:
struct foo
{
public foo() // error!
{
}
}
-
Ok, that clears things up a bit.
Thanks!
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.