Understanding the .NET Framework - The Common Type System
(Page 3 of 8 )
The CTS implements the formal specifications for the type system used by the .NET Framework. All data types represented by the CTS are objects. The CTS defines how a type is defined and the operators that it can accept. One of the primary goals of the CTS is to enable deep language integration by allowing code that's written in one language to be inherited and used by another language. Sharing a common system of data types is one of the most fundamental building blocks that enable this to happen.
Classes of Types
The .NET Framework supports two basic classes of types: value types and reference types. The following section describes these types in more detail.
Value Types - Value types are very similar to the built-in data types provided by most programming languages. Typical data types that are used to store variable values include characters, integers, strings, and floating-point numbers. In the .NET Framework, they are termed value types because they are copied when they are passed as arguments. In other words, they are passed by value. The .NET Framework stores value types on the stack. Table 2-4 lists the value type supported by the .NET Framework along with their VB.NET and C# data type keywords.
Type | Description | VB.NET | C# |
Boolean | A Boolean value (true or false) | Boolean | bool |
Byte | An 8-bit unsigned integer | Byte | byte |
Char | A Unicode (16-bit) character | Char | char |
Decimal | A 96-bit decimal value | Decimal | decimal |
Double | A double-precision (64-bit) floating-point number | Double | double |
Int16 | A 16-bit signed integer | Short | short |
Int32 | A 32-bit signed integer | Integer | int |
Int64 | A 64-bit signed integer | Long | long |
IntPtr | A signed integer whose size depends on the underlying platform | IntPtr | IntPtr |
Object | The root of the object hierarchy | Object | object |
SByte | An 8-bit signed integer | SByte | sbyte |
Single | A single-precision (32-bit) floating-point number | Single | float |
String | An immutable, fixed-length string of Unicode characters | String | string |
UInt16 | A 16-bit unsigned integer | UInt16 | ushort |
UInt32 | A 32-bit unsigned integer | UInt32 | uint |
UInt64 | A 64-bit unsigned integer | UInt64 | ulong |
UIntPtr | An unsigned integer whose size depends on the underlying platform | UIntPtr | UIntPtr |
Table 2-4. CTS Value Types
Reference Types - Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. Unlike value types, reference types are passed between procedures using the address. In other words, a reference to the original object is passed rather than a copy of that object, as is the case with value types.
Type | Description | VB.NET | C# |
Classes | A class is a data structure that may contain data members (constants, variables, and events), function members (methods, properties, indexers, operators, and constructors), and nested types. | Class | class |
Delegates | A delegate is a reference type that refers to a shared method of a type or to an instance method of an object. | Delegate | delegate |
Arrays | An array is a data structure that contains a number of variables (elements of the array). | Dim MyArray(5) As Integer | int[] myArray= |
Interfaces | Interfaces are implemented by other types to guarantee that they support certain operations. An interface defines a contract. A class or structure that implements an interface must adhere to that contract. | Interface | interface |
Pointers | Pointers reference blocks of memory. There are three kinds of pointers supported by the runtime: managed pointers, unmanaged pointers, and unmanaged function pointers. | N/A | int* |
Table 2-5. CTS Reference Types
This is chapter two of ADO.NET: The Complete Reference, by Michael and Denielle Otey (McGraw-Hill/Osborne, ISBN 0-07-222898-9, 2003). Check it out at your favorite bookstore today. Buy this book now. |
Next: The .NET Framework Class Library >>
More .NET Articles
More By McGraw-Hill/Osborne