19-03-2014, 03:56 PM
[u]Programmers Heaven: C# School[/u]
Introduction
The Way
The book is divided in to three progressive levels. In the first beginner stage we will be discussing the .Net
Framework, C# Language Fundamentals and Object Oriented Programming.
In the second intermediate section we will go into depth with Object Oriented constructs such as inheritance,
polymorphism, abstract classes, interfaces, structures, enumerations and exceptions.
In the third and final advanced section we will delve into what is required to implement real world applications
using C# with Base Libraries, focusing on topics such as Collections, Delegates, Events and Windows
Programming with a number of controls, as well as Data Access with ADO.Net, Threads and Streams.
Tools of the trade
Our examples have been written within the standard IDE (Visual Studio.Net). We recommend that you obtain this.
Microsoft are currently offering Visual Studio.Net 2005 Express Edition for free, and this is available at
http://msdn.microsoftvstudio/express/. An alternative open source IDE, SharpDevelop, is available from
http://www.icsharpcodeOpenSource/SD/. It is also possible to use any text editor (such as Notepad) to write
the C# code.
The C# Language
C# (pronounced C-Sharp) is no doubt the language of choice in the .Net environment. It is a whole new language
free of the backward compatibility curse with a whole bunch of new, exciting and promising features. It is an
Object Oriented Programming language and has at its core, many similarities to Java, C++ and VB. In fact, C#
combines the power and efficiency of C++, the simple and clean OO design of Java and the language
simplification of Visual Basic.
MSIL (Microsoft Intermediate Language) Code
When we compile our .Net Program using any .Net compliant language (such as C#, VB.Net or C++.Net) our
source code does not get converted into the executable binary code, but to an intermediate code known as MSIL
which is interpreted by the Common Language Runtime. MSIL is operating system and hardware independent
code. Upon program execution, this MSIL (intermediate code) is converted to binary executable code (native
code). Cross language relationships are possible as the MSIL code is similar for each .Net language.
Just In Time Compilers (JITers)
When our IL compiled code needs to be executed, the CLR invokes the JIT compiler, which compile the IL code to
native executable code (.exe or .dll) that is designed for the specific machine and OS. JITers in many ways are
different from traditional compilers as they compile the IL to native code only when desired; e.g., when a function
is called, the IL of the function's body is converted to native code just in time. So, the part of code that is not used
by that particular run is never converted to native code. If some IL code is converted to native code, then the next
time it's needed, the CLR reuses the same (already compiled) copy without re-compiling. So, if a program runs for
some time (assuming that all or most of the functions get called), then it won't have any just-in-time performance
penalty.
As JITers are aware of the specific processor and OS at runtime, they can optimize the code extremely efficiently
resulting in very robust applications. Also, since a JIT compiler knows the exact current state of executable code,
they can also optimize the code by in-lining small function calls (like replacing body of small function when its
called in a loop, saving the function call time). Although Microsoft stated that C# and .Net are not competing with
languages like C++ in efficiency and speed of execution, JITers can make your code even faster than C++ code in
some cases when the program is run over an extended period of time (like web-servers).
The Framework Class Library (FCL)
The .Net Framework provides a huge Framework (or Base) Class Library (FCL) for common, usual tasks. FCL
contains thousands of classes to provide access to Windows API and common functions like String Manipulation,
Common Data Structures, IO, Streams, Threads, Security, Network Programming, Windows Programming, Web
Programming, Data Access, etc. It is simply the largest standard library ever shipped with any development
environment or programming language. The best part of this library is they follow extremely efficient OO design
(design patterns) making their access and use very simple and predictable. You can use the classes in FCL in your
program just as you would use any other class. You can even apply inheritance and polymorphism to these classes.