Common Type System

Common Type System

In Microsoft's .NET Framework, 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 languages, 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 standard 335, "Common Language Infrastructure (CLI) Partitions I to VI." The CLI and the CTS were created by Microsoft, and the Microsoft .NET framework is an implementation of the standard.

Contents

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.
  • The CTS also specifies the rules for type visibility and access to the members of a type, i.e. the CTS establishes the rules by which assemblies form scope for a type, and the Common Language Runtime enforces the visibility rules.
  • The CTS defines the rules governing type inheritance, virtual methods and object lifetime.
  • Languages supported by .NET can implement all or some common data types

When rounding fractional values, the halfway-to-even ("banker's") method is used by default, throughout the Framework. Since version 2, "Symmetric Arithmetic Rounding" (round halves away from zero) is also available by programmer's option.[1]

  • it is used to communicate with other languages

Type categories

The common type system supports two general categories of types:

Value types 
Value types directly contain their data, and instances of value types are either allocated on the stack or allocated inline in a structure. Value types can be built-in (implemented by the runtime), user-defined, or enumerations.
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. 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 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: {0}, {1}", val1, val2)
        Console.WriteLine("Refs: {0}, {1}", 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 = {0}",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 = {0}",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 o1 = x; // Implicit Boxing
x = (int)o1; // Explicit Unboxing

See also

References

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Common Type System — (сокр. CTS, рус. Стандартная система типов) часть .NET Framework, формальная спецификация, определяющая, как какой либо тип (класс, интерфейс, структура, встроенный тип данных) должен быть определён для его правильного выполнения средой .NET.… …   Википедия

  • Common type system — (CTS, Стандартная система типов)  часть .NET Framework, формальная спецификация, определяющая, как какой либо тип (класс, интерфейс, структура, встроенный тип данных) должен быть определён для его правильного выполнения средой .NET …   Википедия

  • Common Type System — (CTS) est un terme de Microsoft utilisé pour décrire le traitement des types de données dans le Framework .NET. Portail de l’informatique Catégorie : .NET Framework …   Wikipédia en Français

  • Type system — Type systems Type safety Inferred vs. Manifest Dynamic vs. Static Strong vs. Weak Nominal vs. Structural Dependent typing Duck typing Latent typing Linear typing Uniqueness typing …   Wikipedia

  • Type system of the Royal Navy — The Type system is a classification system used by the British Royal Navy to classify surface escorts by function. The system evolved in the early 1950s, when the Royal Navy was experimenting with building single purpose escort vessels with… …   Wikipedia

  • Saffron Type System — The Saffron Type System is a system for rendering high quality scalable type on digital displays. Developed by Mitsubishi Electric Research Laboritories (MERL), Saffron is built on a core of Adaptively Sampled Distance Field (ADF) technology.… …   Wikipedia

  • Common Intermediate Language — (сокращённо CIL)  промежуточный язык, разработанный фирмой Microsoft для платформы .NET Framework. JIT компилятор CIL является частью так называемой CLR (англ. Common Language Runtime)  общей среды выполнения языков .NET. Ранее… …   Википедия

  • Common Language Runtime — (англ. CLR  общеязыковая исполняющая среда)  виртуальная машина, интерпретирующая и исполняющая код на языке CIL, в который компилируются программы, написанные, в частности, на .NET совместимых языках программирования (C#, Managed… …   Википедия

  • Common Language Runtime — El Common Language Runtime o CLR ( entorno en tiempo de ejecución de lenguaje común ) es un entorno de ejecución para los códigos de los programas que corren sobre la plataforma Microsoft .NET. El CLR es el encargado de compilar una forma de… …   Wikipedia Español

  • Common Language Runtime — Pour les articles homonymes, voir CLR. Common Language Runtime (CLR) est le nom choisi par Microsoft pour le composant de machine virtuelle du framework .NET. Il s agit de l implémentation par Microsoft du standard Common Language Infrastructure… …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”