Understanding Common Type System in .NET
 
Published: 08 Jan 2008
Abstract
In this article Suresh examines the concept of Common Type System (CTS) and the purpose behind it. He also discusses the aspects of value and reference types. The article ends with a short explanation of Common Language Specification and some of the common points relevant to CTS.
by Suresh Kumar Goudampally
Feedback
Average Rating: 
Views (Total / Last 10 Days): 29937/ 53

Introduction

The Common Type System (CTS) defines how types are declared, used, and managed in the runtime, and is also an important part of the runtime's support for cross-language integration.

CTS Provides the data types, values, object types. This helps developers to develop applications in different languages, where .NET languages share CTS means all the types used in applications share the same types defined under CLI.

Purpose

1.    Establishes a framework that enables cross-language integration, type safety, and high performance code execution.

2.    Provides an object-oriented model that supports the complete implementation of many programming languages.

3.    Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

Diagram representing Common Type System and categories

Figure 1

      

Value Types and Reference Types

Value Type

A variable of this type represents a piece of data itself. Memory is allocated on the stack.

Listing 1

// Structure , Enumerations and primitive datatypes.
int i = 8;
int i1 = i;
i = 9;

Here, changing one will not have impact on another; the memory here is created twice.

Reference Type

A variable of this category points to the location of data rather than data itself. Memory is created on the heap. Arrays, Classes, Delegates and Interface are examples.

This type is similar to pointers.

Listing 2

Class1 objClass1 = new Class2();
objClass1.Name = "S";
Class1 objClass1Intance = objClass1;
objClass1Intance = "SU";      

Here, both instances refer to the same object, changes to one applies to both.

Common Language Specification

Common Language Specification (CLS) defines a subset of Common Type System, which all language compilers targeting CLR must adhere to. CLS is a subset of CTS.  

All compilers under .NET will generate Intermediate Language no matter what language is used to develop an application. In fact, CLR will not be aware of the language used to develop an application. All language compilers will generate a uniform, common language called Intermediate Language. For this reason IL can be called as the language of CLR A platform for cross language development.

Common Points of Common Type System

1. CTS provides base set of datatypes which is responsible for cross language integration.

2. Most languages use aliases to implement those types (Eg: C# implements int as alias for Int32).

3. CTS is categorized into two types called ValueTypes and ReferenceTypes.

4. Each object in the hierarchy has the common interface.

5. Ensures Type - Safe Code.

Type - Safe Code means given a valid object reference, type-safe code can access memory at fixed offsets corresponding to actual field members.

6. Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

7. Set of Base Types is called CTS.

8. Multiple Inheritance is not allowed in .NET and this can be treated as one of the rules.

9. System.Object is a common base type where all other types are derived from.

10. CTS standardizes the conventions that all the languages must follow.

11. CTS is responsible for defining types that can be used across the .NET Languages.

12. Variables that are Value Type have their own copy of the data.

13. Value Types and Reference Types, all are derived from type called System.Object.

14. Common Language Specification is the subset of Common Type System. (Defines Language rules to be followed.)

15. CTS provides types that are available to be used by programs in .NET and CLS specifies how those type are to be used in a consistent manner to ensure compatibility with other languages.

Conclusion

In this article, you have learned the concept of Common Type System and its purpose. We also examined value and reference types and some of the common points relevant to Common Type System.



User Comments

Title: hey   
Name: hey
Date: 2012-08-08 6:54:00 AM
Comment:
xyz
Title: kuk   
Name: iuyi
Date: 2012-08-08 6:53:37 AM
Comment:
ki8ui8k
Title: book   
Name: lalli
Date: 2012-04-14 11:26:11 AM
Comment:
r
Title: CTS/CLS   
Name: Sonali Joshi
Date: 2010-03-30 12:12:24 AM
Comment:
A really nice articla. it helps me to understand the difference between CLS/CTS also how the concepts works.
Thanks a lot :)
Title: CTS   
Name: Surendra singh
Date: 2009-04-14 6:05:41 AM
Comment:
This helps me to understand CTS in a easy way.It's realy a very helpful to understand.
thanks
Title: CTS   
Name: SHOBANA
Date: 2009-03-25 7:20:50 AM
Comment:
This article is Really helped to me for understand cts. Thank u very much..,
Title: cts   
Name: Deepak
Date: 2009-03-06 1:14:28 AM
Comment:
u have helped me to understand cts.Thnks
Title: COMMON LANGUAGE SPECIFICATION   
Name: JAYSHREE DONGA
Date: 2009-02-10 5:45:58 AM
Comment:
THIS ARTICLE IS REALLY VERY NICE
Title: comman language specification   
Name: mira
Date: 2008-12-27 1:21:58 AM
Comment:
there is very few discription about the CLS
Title: Hi   
Name: Sunny
Date: 2008-05-31 3:44:39 AM
Comment:
Superb, great work.........
Title: Good Notes   
Name: Babitha
Date: 2008-03-07 11:53:18 AM
Comment:
Very Nice.
Title: Hi   
Name: Suresh Kumar
Date: 2008-01-31 7:05:12 AM
Comment:
Hi shivaprasad,
can i know and who r u and

for which company you are working for?


Regards
Suresh Kumar Goudampally
Title: Good notes   
Name: s.k.shivaprasad
Date: 2008-01-31 4:32:59 AM
Comment:
Good work! I would like to see more articles from you in the future



thanks,
s.k.shivaprasad
Software Engineer.
Title: Understanding CTS   
Name: Madhavi G
Date: 2008-01-30 12:04:55 AM
Comment:
Good One, though i am from testing, was able to understand, keep posting such articles.
Title: CTS   
Name: Nitin Sharma
Date: 2008-01-11 2:01:57 AM
Comment:
Good One..!! :-)

Nitin Sharma
Software Engineer
Title: Good Article   
Name: Joydip Kanjilal
Date: 2008-01-10 11:50:31 AM
Comment:
Good work! I would like to see more articles from you in the future.

Thanks,

Joydip

Author: ASP.NET Data Presentation Controls Essentials (Packt Publishing)






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 4:37:13 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search