IL/MSIL/CIL- IL code is a CPU independent
partially compiled code. It’s partially compiled because we do not know in what
kind of environment .Net code will run and on runtime IL Code will compile to
machine code using the environmental properties (CPU, OS, machine configuration
etc). ILDASM- this i
IL/MSIL/CIL- IL code is a CPU independent
partially compiled code. It’s partially compiled because we do not know in what
kind of environment .Net code will run and on runtime IL Code will compile to
machine code using the environmental properties (CPU, OS, machine configuration
etc).
ILDASM- this is tool provided by visual
studio to view IL code. To run ILDASM we have to select option “Visual Studio
Command Prompt” from “Visual Studio Tools” and type ildasm. It will open the
ildasm tool where we can open any exe/dll.ildasm tool read the assembly by
reflection and it is showing us various properties, methods which our assembly
has. Here we can see IL code of any method/property by clicking on that
CLR- CLR is the heart of the .Net framework
and it does 4 primary important things-
1. Garbage collection
2. CAS (Code Access Security)
3. CV (Code Verification)
4. IL to Native translation.
CTS- CTS ensure that data types defined in
two different languages get compiled to a common data type. This is useful
because there may be situations when we want code in one language to be called
in other language.
we can see practical demonstration of CTS by
creating same application in C# and VB.Net and then compare the IL code of both
application. Here the datatype of both IL code is same.
CLS- CLS is a subset of CTS. CLS is a set of
rules or guidelines. When any programming language adheres to these set of
rules it can be consumed by any .Net language.CTS
JIT-JIT compiles the IL code to Machine code
just before execution and then saves this transaction in memory.
CTS
CTS stands for Common Type System. It defines the rules which Common
Language Runtime follows when declaring, using, and managing types. The common
type system performs the following functions:
1. It enables cross-language integration, type safety, and high-performance
code execution.
2. It provides an object-oriented model for implementation of many
programming languages.
3. It defines rules that every language must follow which runs under .NET
framework. It ensures that objects written in different .NET Languages like C#,
VB.NET, F# etc. can interact with each other.
CLS
CLS stands for Common Language Specification
and it is a subset of CTS. It defines a set of rules and restrictions that
every language must follow which runs under .NET framework. The languages which
follows these set of rules are said to be CLS Compliant. In simple words, CLS
enables cross-language integration.
For example, one rule is that you cannot use multiple inheritance
within .NET Framework. As you know C++ supports multiple inheritance but; when
you will try to use that C++ code within C#, it is not possible because C#
doesn’t supports multiple inheritance.
One another rule is that you cannot have
members with same name with case difference only i.e. you cannot have add() and
Add() methods. This easily works in C# because it is case-sensitive but when
you will try to use that C# code in VB.NET, it is not possible because VB.NET
is not case-sensitive.
Why CTS is Called Common Type System?
In .NET, every Data Type is internally
represented by a class or structure. All the classes and structures related to
Data Types are collectively known as CTS. As you know every language provides
its own keywords for Data Types but internally all the languages which run
under .NET framework use the classes and structures available in CTS.
For example, C# has int Data Type and VB.Net has Integer Data Type.
Hence a variable declared as int in C# or Integer in vb.net, finally after
compilation, use the same structure Int32 from CTS.
All the structures and classes available in
CTS are common for all .NET Languages and purpose of these is to support
language independence in .NET. Hence it is called CTS.
What do you think?
I hope, you have enjoyed the article about
CTS and CLS. I would like to have feedback from my blog readers. Your valuable
feedback, question, or comments about this article are always welcome.
No comments:
Post a Comment