Wednesday, October 21, 2009

Value Types

As I've been studying for the Microsoft .NET certification test, I am posting my study notes on my blog.

Value Types


Value Types are types that are copied when passed in as arguments (passed by value).


Value Types are stored on the stack (whereas Reference Types are stored in the Heap). Here is an excellent series of articles about Heap vs. Stack:


C# Heap(ing) Vs Stack(ing) in .NET: Part I


C# Heap(ing) Vs Stack(ing) in .NET: Part II


C# Heap(ing) Vs Stack(ing) in .NET: Part III


C# Heap(ing) Vs Stack(ing) in .NET: Part IV


There are two kinds of Value Types:



  • Built-in value types. These include:


  1. Byte (8-bit unsigned integer, byte)

  2. SByte (8-bit signed integer, byte)

  3. Int16 (16-bit signed integer, short)

  4. Int32 (32-bit signed integer, int)

  5. Int64 (64-bit signed integer, long)

  6. UInt16 (16-bit unsigned integer, ushort)

  7. UInt32 (32-bit unsigned integer, uint)

  8. UInt64 (64-bit unsigned integer, ulong)

  9. Single (32-bit single-precision floating point, float)

  10. Double (64-bit double-precision floating point, double)

  11. Boolean (boolean value true/false, boolean)

  12. Char (16-bit Unicode, char)

  13. Decimal (128-bit, decimal)

  14. IntPtr (signed integer, depends on underlying platform)

  15. UIntPrt (unsigned integer, depends on underlying platform)
  • User-defined Value Types.

The User-defined Value Types will extend System.ValueType or System.Enum. I copied the Complex Number Representation example from MSDN into VS.NET 2008 and played around with it.

Structs are also Value Types. This article from CodeProject covers Enums and Structs.

No comments:

Post a Comment