I have heard the following statement:
We can say class is a datatype or a datatype is one type of class.
Can anyone explain to me wh
Classes are Reference Types.
A Data Type is a value type if it holds the data within its own memory allocation.
Reference types are allocated on the heap, and memory management is handled by the garbage collector. Value types are allocated on the stack or inline and are deallocated when they go out of scope. In general, value types are cheaper to allocate and deallocate.
Like for example
class Person
{
string name;
}
In this the class Person
is reference type and name
is value type i.e data type.
struct Person
{
string name;
}
In this the struct Person
is value type and also name
is value type i.e both are data type.
A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.
In reference to MSDN article on Classes and Structures and also MSDN article on Reference Type and Value Type