All Topics  
Common Type System

 

   Email Print
   Bookmark   Link






 

Common Type System



 
 
The Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information. As used in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s, a Type can be described as a definition of a set of values (for example, "all integers between 0 and 10"), and the allowable operations on those values (for example, addition and subtraction).

The specification for the CTS is contained in Ecma
ECMA

Ecma or ECMA may refer to one of the following:Ecma is short for*Ecma International , formerly : the European Computer Manufacturers Association , an international standards organization for Information Communication Technology and Consumer Electronics ...
 standard 335, "Common Language Infrastructure (CLI) Partitions I to VI." The CLI
Common Language Infrastructure

The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....
 and the CTS were created by Microsoft, and the Microsoft .NET framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
 is an implementation of the standard.


common type system supports two general categories of types: Value types : Value type
Value type

In object-oriented programming, a value type is a data type that can exist outside dynamic memory allocation. Unlike reference types, value types can be directly embedded into composite type....
s directly contain their data, and instances of value types are either allocated on the stack
Call stack

In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program....
 or allocated inline in a structure.






Discussion
Ask a question about 'Common Type System'
Start a new discussion about 'Common Type System'
Answer questions from other users
Full Discussion Forum



Encyclopedia


The Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information. As used in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s, a Type can be described as a definition of a set of values (for example, "all integers between 0 and 10"), and the allowable operations on those values (for example, addition and subtraction).

The specification for the CTS is contained in Ecma
ECMA

Ecma or ECMA may refer to one of the following:Ecma is short for*Ecma International , formerly : the European Computer Manufacturers Association , an international standards organization for Information Communication Technology and Consumer Electronics ...
 standard 335, "Common Language Infrastructure (CLI) Partitions I to VI." The CLI
Common Language Infrastructure

The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....
 and the CTS were created by Microsoft, and the Microsoft .NET framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
 is an implementation of the standard.

Functions of the Common Type System

  • To establish a framework that helps enable cross-language integration, type safety, and high performance code execution.
  • To provide an object-oriented model that supports the complete implementation of many programming languages.
  • To define rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.
  • The CTS also defines the rules that ensures that the data types of objects written in various languages are able to interact with each other.


Type categories

The common type system supports two general categories of types: Value types : Value type
Value type

In object-oriented programming, a value type is a data type that can exist outside dynamic memory allocation. Unlike reference types, value types can be directly embedded into composite type....
s directly contain their data, and instances of value types are either allocated on the stack
Call stack

In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program....
 or allocated inline in a structure. Value types can be built-in (implemented by the runtime), user-defined, or enumerations. Reference types : Reference type
Reference type

In Object-oriented programming, a reference type is a data type that can only be accessed by Reference . Unlike objects of value types, objects of reference types cannot be directly embedded into composite type and are always Dynamic memory allocation....
s store a reference to the value's memory address, and are allocated on the heap
Dynamic memory allocation

In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program....
. Reference types can be self-describing types, pointer types, or interface types. The type of a reference type can be determined from values of self-describing types. Self-describing types are further split into arrays and class types. The class types are user-defined classes, boxed value types, and delegates.

The following example written in Visual Basic .NET
Visual Basic .NET

Visual Basic , formerly called Visual Basic .NET , is an object-oriented programming computer language that can be viewed as an evolution of Microsoft Visual Basic implemented on the .NET Framework....
 shows the difference between reference types and value types: 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: , ", val1, val2) Console.WriteLine("Refs: , ", ref1.Value, ref2.Value) End Sub 'Main End Class 'Test The output of the above example

Values: 0, 123 Refs: 123, 123

Boxing and unboxing


Boxing

Converting value types to reference types is also known as boxing. As can be seen in the example below, it is not necessary to tell the compiler an Int32 is boxed to an object, because it takes care of this itself. Int32 x = 10; object o = x ; // Implicit boxing Console.WriteLine("The Object o = ",o); // prints out 10 However, an Int32 can always be explicitly boxed like this: Int32 x = 10; object o = (object) x; // Explicit boxing Console.WriteLine("The object o = ",o); // prints out 10

Unboxing

The following example intends to show how to unbox a reference type back to a value type. First an Int32 is boxed to an object, and then it is unboxed again. Note that unboxing requires explicit cast. Int32 x = 5; object o = x; // Implicit Boxing x = (int)o; // Explicit Unboxing

See also

  • .NET Framework
    .NET Framework

    The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
  • Blittable types
    Blittable types

    Blittable types are data types in software applications which have a unique characteristic. Data are often represented in memory differently in Managed code and unmanaged code in the Microsoft .NET framework....
  • Common Language Infrastructure
    Common Language Infrastructure

    The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....


External links