The C# LanguageC# is a new and modern programming language provided as part of the .NET Framework. It is an Object Oriented Programming language and has it's core many similarities with Java and C++. Some of the attributes by this language includes :
- C# does not allow multiple inheritance but allows multiple implementation of interfaces
- Provides Garbage Collection so that programmers does not need to worry of memory allocations and pointers.
- It maintains unique operations of C++ like operator overloading, enumerations, pre-processor directives, delegates (or function pointers in C++)
- It supports concepts of properties, reflections, attributes, marshalling, remoting, threads, streams, data access etc.
The .NET Framework
.NET framework is a new framework which includes large libraries called Framework Class Library, allows and it supports several programming languages which allows language interoperability (each language can use code written in other languages). The .NET library is available to all the programming languages that .NET supports. Some of the languages it supports includes C#, F#, VB.NET, C++ among others.
The most important piece of this framework is the CLR or Common Language Runtime. It is a framework that sits on top of the OS and allows execution of the language developed for .NET framework. We can show it by the below diagram.
*From Programmers Heaven C# School Book
Common Language Runtime (CLR)CLR or Common Language Runtime is an environment at which we can run our .NET Applications that have been compiled by IL Compiler. If you are familiar with Java, consider CLR as JRE.
To further breakup CLR, a diagram is shown below : (1)
- Common Type System- It is responsible for interpreting data types for .NET framework. E.g. how many bytes there is in a String object. CTS defines the basic data types to what an IL can understand. Each language should map it's data types to these standard data types. This is quite powerful and allows 2 languages to understand each other such as passing and receiving parameters to each other.
- IL Compiler - IL Compiler compiles the IL Code to the Machine Language. IL actually means Intermediate Language. When you compile your code, the code gets compiled to an Intermediate Language, much like a Java is compiled to a Java Byte Code. However, afterwards, this IL will be fed to the CLR so that it gets compiled to a machine language code.
- Execution Support - It is similar to the language runtime (e.g. VBRunxxx.dl in VB however in .NET there's no individual language runtimes anymore).
- Security - Provides the security context on the application, and ensures the application has permission to certain functions.
- Garbage Collector - It is similar to the garbage collector found in Java, which collects stale objects or unused/unreferenced objects, and releases the allocation to the heap memory.
- Class Loader - The purpose is to load the classes needed by the application.
To understand, here's a sample :
- Programmer writes the source code and compiles it.
- Language compiler compiles it to IL. ( This is called Assembly )
- WHen the applciation is run the following happens :
- It checks the assembly's security characteristics.
- It allocates space in memory.
- It sends the assembly to the IL Compiler (also called Just-in-time compiler) which compiles portions of it to native machine code. Only portions of the code is compiled as it is needed. If it's not needed during execution, it is not compiled.
The diagram below from the book Beginning ASP.NET in C# 2010 shows how the compilation works.
.Net Framework also provides a large and extensive library called Framework Class Library (or Base Class Library). It's sole purpose is to provide easy to use API's that are available to your application, such as :
- General Base Classes - Classes that provides set of tools for programming tasks such as file manipulation, string manipulation, security, encryption, etc.
- Collection Classes - Classes that implements lists, hashtables, etc.
- Threading and Synchronization classes - Classes for building multi-threaded programs
- XML Classes - Classes for XML manipulation
- Data Classes - Classes used for Data Access and manipulation.
Post a Comment