FACTOID # 79: Australians are the most likely to join charities, educational organizations, environmental groups, professional organizations, sports groups and unions. But only three percent join political parties.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Common Type System

The Common Type System (CTS) is used by every language built on the .NET Framework. A fundamental part of the .NET Framework is Common Language Runtime (CLR), the CTS specifies no particular syntax or keywords, but instead defines a common set of types that can be used with many different language syntaxes. Each language is free to define any syntax it wishes, but if that language is built on the CLR, it will use at least some of the types defined by the CTS. While the creator of a CLR-based language is free to implement only a subset of the types defined by the CTS. Visual Basic.NET, C#, and pretty much every other language used with the .NET Framework rely heavily on the CTS. The Microsoft . ... The Common Language Runtime (CLR) is the virtual machine component of Microsofts . ... Visual Basic . ... The title given to this article is incorrect due to technical limitations. ...

Contents

Overview

The CTS provides every language running on the .NET platform with a base set of data types. While the CTS is responsible for defining the types that can be used across the .NET languages, most languages choose to implement aliases to those types. For example, a four-byte integer value is represented by the CTS type System.Int32. C# defines an alias for this called type called int.


Everything in the CTS is an object. Not only is everything an object but even more importantly, all objects implicitly derive from a single base class defined as a part of the CTS. This base class is called System.Object. The designers of CTS were faced with the task of creating a type system in which every thing is an object, but the type system works in an efficient manner, when applicable.


Why the need for a CLR and CTS?

Each programming language tends to bring its own datatypes with it. For example, VB represents strings using the BSTR struct, C++ uses arrays of char/wchar_t or the std::string class, and Microsoft Foundation Classes uses the CString class. The int datatype in 32-bit versions of Visual C++ is a 32-bit value where the Visual Basic integer datatype, prior to VB.NET, is a 16-bit value. C++ (pronounced see plus plus, IPA: ) is a general-purpose, high-level programming language with low-level facilities. ... Microsoft Foundation Classes, or MFC, is a Microsoft library that wraps portions of the Windows API in C++ classes, forming an application framework. ... Visual Basic (VB) is an event driven programming language and associated development environment from Microsoft for its COM programming model. ... Visual Basic . ...


One of the goals of the .NET platform is to make it easier for the developer to write applications. COM developers are exposed to a headache as they need to be concerned about GUIDs, HRESULTs, early versus Late binding, managing reference counts, the type of threading model your component will run in, and proxy and stub layers etc. Fortunately, some of the programming environment and frameworks such as Visual Basic and Active Template Library come to the rescue, reducing much of this complexity. Visual Basic, for example, automatically generates the appropriate GUIDs and manages reference counts for Component Object Model objects used within the application. Still, many developers will argue that Visual Basic's implementation of COM leaves a lot to be desired. The solution has been presented in the form of creating such a system which is common to all the languages related to this platform and so the common type system was created. Bottle of >.net A Globally Unique Identifier or GUID is a pseudo-random number used in software applications. ... The introduction to this article provides insufficient context for those unfamiliar with the subject matter. ... The Active Template Library (ATL) is a set of template-based C++ classes that simplify the programming of Component Object Model (COM) objects. ... Component Object Model (COM) is a Microsoft platform for software componentry introduced by Microsoft in 1993. ...


The functions of Common Type System

  • Establishes a framework that helps enable cross-language integration, type safety, and high performance code execution.
  • Provides an object-oriented model that supports the complete implementation of many programming languages.
  • Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ...

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 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


convert ValueTypes to Reference Types also known as boxing. Lets see a small example below. You see in the example I wrote "implicit boxing" which means you don't need to tell the compiler that you are boxing Int32 to object because it takes care of this itself although you can always make explicit boxing as seen below right after implicit boxing.

 Int32 x = 10; object o = x ; // Implicit boxing Console.WriteLine("The Object o = {0}",o); // prints out 10 //----------------------------------------------------------- Int32 x = 10; object o = (object) x; // Explicit Boxing Console.WriteLine("The object o = {0}",o); // prints out 10 

Unboxing


Lets now see UnBoxing an object type back to value type. Here is a simple code that unbox an object back to Int32 variable. First we need to box it so that we can unbox.

 Int32 x = 5; object o = x; // Implicit Boxing x = o; // Implicit UnBoxing 

See also

good for learning The Microsoft . ... Blittable types is a phrase used in the context of marshalling data types between managed and unmanaged code in the Microsoft . ...


External links

  • Microsoft developer's guide describing the CTS
  • built-in types in the .NET Framework


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.