Search This Blog

Sunday, August 7, 2011

C# 4.0 – Ch:01:A – Introduction


If you like this article, please click on +1 button and share with your friends.

Click here for the Video Tutorial of this article.
visit www.iGnani.com


C#—pronounced “See Sharp”—is a programming language designed for Microsoft’s .NET platform. C# is a general-purpose, type-safe, object-oriented programming language. The chief architect of the language since its first version is Anders Hejlsberg (creator of Turbo Pascal and architect of Delphi). The goal of C# is to provide a simple, safe, modern, object-oriented, Internet-centric, high-performance language for .NET development.
C# was first announced in July 2000 with the announcement of the .NET platform by Microsoft. It was released in January 2002 with .NET framework 1.0. C# was first called “Cool” which stood for "C-like Object Oriented Language”.
C# is a strongly typed object-oriented language whose code visually resembles C++ (and Java). This decision by the C# language designers allows C++ developers to easily leverage their knowledge to quickly become productive in C#. C# syntax differs from C++ in some ways, but most of the differences between these languages are semantic and behavioral, stemming from differences in the runtime environments in which they execute.

220px-Anders_Hejlsberg
Anders Hejlsberg

.NET & C#

.NET is designed to provide an environment within which you can develop almost any application to run on Windows, while C# is a programming language that has been designed specifically to work with the .NET Framework.

Using C#, you can develop Windows Desktop applications, Write a dynamic web page with ASP.net, a WPF Application, XML Web service or WCF components for distributed application, or even a smart client application that allows for online/offline capabilities and much much more. It has been evolving since its first release in 2002. C# and .NET have revolutionized the way developers write their programs and have made programming on Windows much easier than it was before. .NET is a framework — for programming on the Windows platform. C# is the language that was designed from scratch to work with .NET.

The Common Language Runtime

CLR short for Common Language Runtime is also know as .NET runtime. The CLR is just what its name says: a runtime execution environment for .NET Framework. Code running under the control of the CLR is termed as managed code.

Language Interoperability

All the programming languages that are supported by .NET Framework use CLR to execute the code. All the core features of the CLR such as memory management, assembly loading, security, exception handling, thread synchronization etc., are available to all programming languages that target the CLR. In fact, at runtime the CLR cannot know the programming language the developer used. This makes it easy for people to develop .NET applications using the programming language for their choice.

Microsoft created several language compilers that target the runtime: C++/CLI, C#, Visual Basic, F#, Iron Python, Iron Ruby, and an Intermediate Language (IL) Assembler. In addition to Microsoft, various colleges, universities & companies have created compilers that produce code to target the CLR. Some of these compilers are Ada, APL, Caml, COBOL, Eiffel, Forth, Fortran, Haskell, Lexico, LISP, LOGO, Lua, Mercury, ML, Mondrian, Oberon, Pascal, Perl, Php, Prolog, RPG, Scheme, Smalltalk, and Tcl/Tk.

Code written in any of the above mentioned programming languages has to be compiled before it can be executed by the CLR. Compilation occurs in two stages:

Compilation of source code to Microsoft Intermediate Language (IL).

Regardless of the compiler, the result is always a managed code which is the IL code. A managed module is a standard 32-bit Microsoft Windows portable executable (PE32) file or a standard 64-bit Windows portable executable (PE32+) file that requires the CLR to execute. In other words, all CLR-compliant compilers produce IL code. IL code is sometimes referred to as managed code since it is managed by CLR.

Compilation of IL to platform-specific code by the JIT Compiler in the CLR

JIT short for Just-In-Time is what compiles the IL Code into platform specific code. Instead of compiling the entire application at one shot, the JIT compiler simply compiles each portion of code as it is called (just in time).

This two-stage compilation process is very important, because the existence of the Microsoft Intermediate Language is the key to providing many of the benefits of .NET.

Platform independence

Platform independence means that the same file containing IL code can be executed on any platform. As mentioned above, the JIT compiles the IL code to platform specific code just before executing it. In other words, by compiling to IL you get platform independence for .NET. However, the CLR is only available to Linux and Windows environment which makes it theoretically capable of being executed on these two OS’s.

Performance improvement

With JIT compilation, once the code has been compiled into a native executable, it is stored until the application exits so that it does not need to be recompiled the next time that portion of code is run. This process is more efficient than compiling the entire application code at the start, because the likelihood that large portion of any application code will actually being executed in any given run is very minute. Using the JIT compiler, such code will never be compiled. This is the reason why the managed IL Code execution is almost as fast as executing native machine code. Not just that, but since the JIT compiler knows exactly what processor type the program will run on, the code is precisely compiled to the match the type of processor. This means that the JIT can optimize the final executable code to take advantage of any features offered by that particular processor.

Next article “ C# 4.0 – Ch:01:B – Close-up with .NET”…

visit www.iGnani.com

MicroMind Information Systems
#4013, K.R. Road, Banashankari II Stage,
BANGALORE - 560070
KARNATAKA, INDIA
Phone: +91 80 26762747

No comments:

Post a Comment