reference types and value types

i understand that
Point p;
is creating a value type
and
Foo f = new Foo();
is reference type...
so can i say that when we use the new keyword..it becomes a refernce type??
are there more differences?
tks for any help....
[267 byte] By [Joseph_R_Thomas] at [2007-11-18 13:41:29]
# 1 Re: reference types and value types
Variables of reference types, referred to as objects, store references to the actual data. The following keywords are used to declare reference types: class, interface, delegate and the built-in reference types: object and string.

A variable of a value type always contains a value of that type. The assignment to a variable of a value type creates a copy of the assigned value, while the assignment to a variable of a reference type creates a copy of the reference but not of the referenced object.
All value types are derived implicitly from the Object class.
Unlike reference types, it is not possible to derive a new type from a value type. However, like reference types, structs can implement interfaces.
Unlike reference types, it is not possible for a value type to contain the null value.
Each value type has an implicit default constructor that initializes the default value of that type.

With user-defined types, use new to invoke the default constructor. For example, the following statement invokes the default constructor of the Point struct:

Point p = new Point(); // Invoke the default constructor for the struct
After this call, the struct is considered to be definitely assigned; that is, all of its members are initialized to their default values.
vma at 2007-11-9 1:34:59 >
# 2 Re: reference types and value types
Originally posted by vma
Variables of reference types, referred to as objects, store references to the actual data. The following keywords are used to declare reference types: class, interface, delegate and the built-in reference types: object and string.

A variable of a value type always contains a value of that type. The assignment to a variable of a value type creates a copy of the assigned value, while the assignment to a variable of a reference type creates a copy of the reference but not of the referenced object.
All value types are derived implicitly from the Object class.
Unlike reference types, it is not possible to derive a new type from a value type. However, like reference types, structs can implement interfaces.
Unlike reference types, it is not possible for a value type to contain the null value.
Each value type has an implicit default constructor that initializes the default value of that type.

With user-defined types, use new to invoke the default constructor. For example, the following statement invokes the default constructor of the Point struct:

Point p = new Point(); // Invoke the default constructor for the struct
After this call, the struct is considered to be definitely assigned; that is, all of its members are initialized to their default values.
very informative...tks a lot..:)
Joseph_R_Thomas at 2007-11-9 1:35:51 >
# 3 Re: reference types and value types
if possible can u expand these two lines please?All value types are derived implicitly from the Object class.
Unlike reference types, it is not possible to derive a new type from a value type. However, like reference types, structs can implement interfaces.

tks a lot...
Joseph_R_Thomas at 2007-11-9 1:36:55 >
# 4 Re: reference types and value 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.

A struct declaration may include a struct-interfaces specification, in which case the struct is said to implement the given interface types.

struct-interfaces:
; interface-type-list

For more detailed informations about Interface implementations you can read the "C# Language Specification" Chapter 13.4 "Interface implementations"
vma at 2007-11-9 1:38:01 >