Intro to C# I

Share if you like...Share on Facebook0Tweet about this on TwitterShare on Google+0Share on LinkedIn0

Microsoft.NET is the set of new technologies that Microsoft has been working in recent years in order to obtain a simple and powerful platform for distributing the software as services that can be provided remotely and can communicate and combined with one another completely independent of the platform, programming language and model components that have been developed. This is called .NET platform, as previously mentioned services are called Web services.

To develop apps using .NET, both services and traditional applications (console applications, windows applications, Windows NT services, etc.), Microsoft has published the software development kit known .NET framework SDK, which includes needed tools to develop, distribute, execute and Visual Studio.NET, which allows all of the above from an visual interface based on windows. Both tools can be downloaded for free from, although the last one is only available for subscribers in MSDN universal (those who aren’t subscribers can ask for it in the previous link and will be sent for free by regular post).

The concept of Microsoft.NET includes too the set of new technologies that Microsoft and third have developed to be used in .NET platform.

Among them we can highlight applications developed by Microsoft like Windows.NET, Hailstorm, Visual Studio.NET, MSN.NET, Office.NET, and the new Microsoft’s servers for enterprises (SQL Server.NET, Exchange.NET, etc.)

Common Language Runtime (CLR)

Common Language Runtime (CLR) is the core of the .NET platform. This is the motor aimed to manage the execution of the applications developed for it and offers many services to simplify the development and makes the applications safest and more reliable. The main characteristics and services provided by CLR are:
Consistent Programming Model: All services and facilities offered by CLR are accessed in the same way: through Objects Oriented Programming (OOP). This is an important difference in comparison to other systems in which the services are accessed through global functions in DLLs or through objects (COM objects in Windows family for example).

Easy programming model: With CLR most of the complex elements included in current OS disappear (Windows reg., GUIDs, HRESULTS, IUnknown, etc.). CLR doesn’t abstract to programmer from these concepts, but these concepts doesn’t exists in .NET.

Elimination of the “DLL Hell”: In .NET disappears the problem known as “DLL Hell” given in the current Windows family OS. This problem consists in when old DLL versions, shared by multiple applications, are updated to new versions, those applications designed for old versions may not work anymore if the new DLL version isn’t 100% compatible with the old one. In .NET old and new DLL versions can coexist, avoiding this problem. This, obviously, simplifies so much installation and removal of software.

Multiplatform execution: CLR works as a virtual machine, being responsible of the execution of applications designed for .NET. That is, any platform provided with a version of the CLR can execute any .NET application. Microsoft has developed CLR versions for most of Windows versions: Windows 95, Windows 98, Windows ME, Windows NT 4.0, Windows 2000, Windows XP, Windows CE… On the other hand, Microsoft has signed agreements with Corel to port the CLR to Linux, and thirds are developing free distributions of the CLR for Linux. Also, due to the architecture of the CLR is open source, it’s possible that in the future new versions will be designed for other OS.

● < Language integration: ability to derive a class from a base that is specified in a totally different language; to catch exceptions thrown by code written in a different language; or to take advantage of polymorphism across different languages, and so forth.
Microsoft has developed a compiler for C# that compiles this kind of code, as well as in its compilers for Visual Basic (Visual Basic.NET) and C++ (C++ with managed extensions), which compiles it too, and an interpreter for JScript (JScript.NET). Thanks to the language integration it’s possible to write a class using C# which inherit from another written in Visual Basic.NET, which in turn inherit from another written in C++.

Memory management: CLR includes a garbage collector which avoids to the programmer to keep in mind when is needed to destroy the unuseful objects. This collector is an application activated when creating a new object, and there’s no free memory for it. In this case the collector goes over the dynamic memory associated to the application, detects which objects are there that cannot be accessible by the application’s code and delete them to clean the memory, allowing to create new objects. Thanks to this collector many common programming mistakes are avoided, i.e. trying to remove removed objects, being out of memory due to not to have removed unuseful objects, or trying to access destroyed objects.

Security of types: CLR facilitates detecting programming errors which are hard to be found checking that all conversion of types done during the execution of an application are done in a way in which origin and destiny types are compatible.

Sandbox: CLR assures that from code belonging to a particular process cannot access to data belonging to another, avoiding frequent programming mistakes and prevents a process to be attacked by others.
This is thanks to the security of types previously explained, avoiding to convert an object to a type of larger size than the itself, because by treating it as an object with larger size, it could access to alien memory spaces that could pertain to another process. It’s too thanks to it’s not allowed to access to random memory positions.

Exception Handling: In the CLR all the errors that can happen are spread in the same way: through exceptions. This is a different way in comparison to how it was done in Windows OS until the creation of .NET, where some errors were spread through error codes with Win32 format, others through HRESULTs and others through exceptions.
CLR allows that launched exceptions from code for .NET, written in a certain language, can be caught by code written in another language, and includes debugging mechanisms which can goes from a code written for .NET in a particular language to code written in another language. I.e., an exception stack can be toured even though it includes methods defined in other modules using other languages.

Multi-thread support: CLR can works with application divided in multiple executing thread. Applications can create new threads, destroy them, suspend them for a time or until are notified, send notifications, synchronize them, etc.

Transparent distribution: CLR offers the needed infrastructure to create remote objects and access them in a completely transparent way to its real localization, as if they were on the machine that uses them.

Advanced security: CLR gives mechanisms to restrict the execution of certain codes or to the assigned permissions to them based on its origin or the user that executes them. That is to say, it can be given a different confidence level to a code from Internet that a code installed locally or from a local network, or different confidence level to a manufacturer than to another… This allows to ensure to the system admin. that the running code cannot endanger the integrity of his files, the windows reg., etc.

Interoperability with old code: CLR includes mechanisms needed to access to code written for .NET to code written before its appearance, therefore not prepared to be executed on it. These mechanisms allow both accesses, to COM objects as preexisting single DLLs functions (for example Win32 API).

As it can be deduced from the commented characteristics, the CLR manages the execution of applications designed for .NET. For this reason, the code of these applications is usually named managed code, and the code not written to be executed directly in .NET is usually named not managed code.

Introducción a C# II.

Share if you like...Share on Facebook0Tweet about this on TwitterShare on Google+0Share on LinkedIn0
The following two tabs change content below.
Reborn as IT Developer. Desarrollador Android y fundador de Proyecto Simio. "En realidad, yo no puedo enseñar nada a nadie, sólo puedo hacerles pensar." - Sócrates.

Leave a Reply