The Dot Net Common Type System


This section describes concepts and defines terms that will help you understand and work with your language's implementation of the common type system.

Classification of Types

The common type system supports two general categories of types, each of which is further divided into subcategories:

Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable.

All types derive from the System.Object base type.

The following example shows the difference between reference types and value types.

[Visual Basic]
Imports System

Class Class1
    Public Value As Integer = 0
End Class 'Class1

Class Test
    
    Shared Sub Main()
        Dim val1 As Integer = 0
        Dim val2 As Integer = val1
        val2 = 123
        Dim ref1 As New Class1()
        Dim ref2 As Class1 = ref1
        ref2.Value = 123
        Console.WriteLine("Values: {0}, {1}", val1, val2)
        Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value)
    End Sub 'Main
End Class 'Test
[C#]
using System;
class Class1
{
public int Value = 0;
}
class Test
{
    static void Main() {
        int val1 = 0;
        int val2 = val1;
        val2 = 123;
        Class1 ref1 = new Class1();
        Class1 ref2 = ref1;
        ref2.Value = 123;
        Console.WriteLine("Values: {0}, {1}", val1, val2);
        Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value);
    }
}

The output from this program is as follows.

Values: 0, 123
Refs: 123, 123

The following diagram illustrates how these various types are related. Note that instances of types can be simply value types or self-describing types, even though there are subcategories of these types.

Type classification

Values and Objects

Values are binary representations of data, and types provide a way of interpreting this data. A value type is stored directly as a binary representation of the type's data. The value of a reference type is the location of the sequence of bits that represent the type's data.

Every value has an exact type that completely defines the value's representation and the operations that are defined on the value. Values of self-describing types are called objects. While it is always possible to determine the exact type of an object by examining its value, you cannot do so with a value type or pointer type. A value can have more than one type. A value of a type that implements an interface is also a value of that interface type. Likewise, a value of a type that derives from a base type is also a value of that base type.

Types and Assemblies

The runtime uses assemblies to locate and load types. The assembly manifest contains the information that the runtime uses to resolve all type references made within the scope of the assembly.

A type name in the runtime has two logical parts: the assembly name and the name of the type within the assembly. Two types with the same name but in different assemblies are defined as two distinct types.

Assemblies provide consistency between the scope of names seen by the developer and the scope of names seen by the runtime system. Developers author types in the context of an assembly. The content of the assembly a developer is building establishes the scope of names that will be available at run time.

Types and Namespaces

From the viewpoint of the runtime, a namespace is just a collection of type names. Particular languages might have constructs and corresponding syntax that help developers form logical groups of types, but these constructs are not used by the runtime when binding types. Thus, both the Object and String classes are part of the System namespace, but the runtime only recognizes the full names of each type, which are System.Object and System.String, respectively.

You can build a single assembly that exposes types that look like they come from two different hierarchical namespaces, such as System.Collections and System.Windows.Forms. You can also build two assemblies that both export types whose names contain MyDll.MyClass.

If you create a tool to represent types in an assembly as belonging to a hierarchical namespace, the tool must enumerate the types in an assembly or group of assemblies and parse the type names to derive a hierarchical relationship.

The System namespace is the root namespace for fundamental types in the .NET Framework. This namespace includes classes that represent the base data types used by all applications: Object (the root of the inheritance hierarchy), Byte, Char, Array, Int32, String, and so on. Many of these types correspond to the primitive data types that your programming language uses. When you write code using .NET Framework types, you can use your language's corresponding keyword when a .NET Framework base data type is expected.

The following table lists some of the value types the .NET Framework supplies, briefly describes each type, and indicates the corresponding type in Visual Basic, C#, and the Managed Extensions for C++. The table also includes entries for the Object and String classes, for which many languages have corresponding keywords.

Category Class name Description Visual Basic data type C# data type Managed Extensions for C++ data type JScript data type
Integer Byte An 8-bit unsigned integer. Byte byte char Byte
    SByte An 8-bit signed integer.

Not CLS-compliant.

SByte

No built-in type.

sbyte signed char SByte
    Int16 A 16-bit signed integer. Short short short short
    Int32 A 32-bit signed integer. Integer int int

-or-

long

int
    Int64 A 64-bit signed integer. Long long __int64 long
    UInt16 A 16-bit unsigned integer.

Not CLS-compliant.

UInt16

No built-in type.

ushort unsigned short UInt16
    UInt32 A 32-bit unsigned integer.

Not CLS-compliant.

UInt32

No built-in type.

uint unsigned int

-or-

unsigned long

UInt32
    UInt64 A 64-bit unsigned integer.

Not CLS-compliant.

UInt64

No built-in type.

ulong unsigned __int64 UInt64
Floating point Single A single-precision (32-bit) floating-point number. Single float float float
    Double A double-precision (64-bit) floating-point number. Double double double double
Logical Boolean A Boolean value (true or false). Boolean bool bool bool
Other Char A Unicode (16-bit) character. Char char wchar_t char
    Decimal A 96-bit decimal value. Decimal decimal Decimal Decimal
    IntPtr A signed integer whose size depends on the underlying platform (a 32-bit value on a 32-bit platform and a 64-bit value on a 64-bit platform). IntPtr

No built-in type.

IntPtr

No built-in type.

IntPtr

No built-in type.

IntPtr
    UIntPtr An unsigned integer whose size depends on the underlying platform (a 32- bit value on a 32-bit platform and a 64-bit value on a 64-bit platform).

Not CLS-compliant.

UIntPtr

No built-in type.

UIntPtr

No built-in type.

UIntPtr

No built-in type.

UIntPtr
Class objects Object The root of the object hierarchy. Object object Object* Object
    String An immutable, fixed-length string of Unicode characters. String string String* String

In addition to the base data types, the System namespace contains almost 100 classes, ranging from classes that handle exceptions to classes that deal with core runtime concepts, such as application domains and the garbage collector. The System namespace also contains many second-level namespaces.

 

[ Home ] [Services] [ Customers]
Send mail to webmaster@ninestein.com with questions or comments about this web site.
Copyright © 2000 Ninestein Technologies
Last modified: March 16, 2004