Tuesday, May 11, 2010

Value Types and Reference Types

Value Types
  • Allocated on the stack.
  • Value type variables are local copies.
  • Value types are deived from System.ValueType
  • Values types are always sealed and cannot be extended.
  • Variables are passed by value( copy of the variable is passed into the called function )
  • Value types are never placed onto the heap and therefore do not need to be finalized.
  • The variable of this type die when they fall out of the defining scope.
Reference Types
  • Allocated on the managed heap
  • Reference type variables are pointing to the memory occupied by the allocated instance
  • Variables are passed by reference( address of the variable is passed to the called function )
  • The variable of this type die when they are garbage collected.
Nullable Types
Value types can never be assigned the value of null.


the ? suffix notation is a shorthand for creating an instance of the generic System.Nullable structure type.
?? operator allows o assign a value to a nullable type if the retrieved value is in fact null.




 

No comments:

Post a Comment