Friday 30 May 2014

Learn C# Programming Tutorial Part 1 : Getting Started

Getting Started in C# - Tutorial



Madan Gehlot

Version 1.1

Copyright 2014

21.02.2014

Introduction to Dot Net Framework and C#


This tutorial describe history of Dot Net Framework , Platform Advantage , How program are executed and Setting up Development Environment.

Table Of Contents

1. Getting started
   1.1. Dot NetFramework
   1.2. Platform Advantage
   1.3. Platform Programming
   1.4. Development Environment Setup

1.1Dot Net Framework:

When Internet started to grown fast after 1995, Microsoft realised that direction of Web Development and Deployment will depends on growth of Internet, so they started to design and development of .NET platform keeping future of technology in mind.
When Microsoft was thinking of developing a new programming platform, at the same time, the Sun microsystem’s JAVA was very popular in the area of web development and Visual Basic was going viral for Desktop Programming. Microsoft didn’t want to leave the battle.
They inspired from JAVA to design such a programming language that have Security and Extendibility.They emphasised on the importance of Rapid and Easy Development.
Thus Microsoft decided to develop a Programming Language which has all essential concepts of programming. C# was the result of such efforts.
C # (C Sharp) is much similar to C/C++, JAVA and Visual Basic. C # is similar to JAVA from the Classes and Platform points of view, similar to Visual Basic from the GUI point of view, similar to C++ for Object Oriented Concepts and similar to C for Coding Structure.
C# also has Hardware level interaction capacity like C language. The architecture like JAVA language makes it more Secure and Powerful. Visual Basic like GUI feature enables it for Rapid Application Development.
Dot Net Framework was developed to make the programming architecture Future Proof, manage portability and manage Web and Windows application from single platform.
In .Net Framework, every .Net application includes Run time and Compile time services. These are Servers, COM, COM+ , DCOM, Internet Information Server , Windows .Net Server and SQL Server etc.
.Net Application Code has CLR( Common Language Runtime) in the root of Run Time Execution.
Purpose of CLR is same as that of JVM in JAVA. IT acts like Virtual Machine. CLR makes .Net code platform independent.
A program developed on a computer system having CLR can also be run on any other computer that has CLR. When we compile Dot Net Application, it generates .DLL or .EXE codes.We call them Portable Executable (PE) codes. These generated codes are not Native or Machine level but a kind of intermediate byte code.
Intermediate Codes are known as Microsoft Intermediate Language(MSIL) or simply IL.
When codes are loaded into CLR for execution, we call such code “ASSEMBLY” .Assembly is one or more file collection. All files are deploying as single unit. There is a Manifest file in Assembly which contain Data Types, Classes and files.
When CLR loads application into memory, only MANIFEST file is compiled in memory. Data Types and Classes are compiled only when there is need.  Because of this, .NET application load faster in memory and uses less resources. This process is called Just In Time compilation. As a result, there is no leakage of memory.
Garbage Collector automatically free up the Memory once there is no use of any Objects.

1.2 NET Platform Advantage:

Before proceeding, we will discuss the features of .NET platform that are helpful in developing Software and Services.

Object Oriented Programming:

Dot Net Framework was completely designed based on Object Oriented Programming Paradigm. We can extend any application using OOPs. Design and Management of software becomes easy using OOPs concepts.

Multiple Language Support:

Dot Net platform not only support C# and Visual Basic but also C++ and F#. More languages are being added at appropriate time.
We can develop even Android Based application using C#.

Simple Application Deployment:

Dot Net application are easy tom deploy because it don’t require registration like COM based application.

Rich Framework Class Library:

.Net has rich collection of Class Library. It is the perhaps only language which has features in rich Class libraries. We need framework class library to full fill specific achievement while developing any application.

Exception Handling:

This technique was designed to manage error in applications. Exception Handling works in the same way as C++ / JAVA Exception Handling mechanism works.

Improved Security:

Security is serious concern of code deployment. So Microsoft created Code Access Security (CAS) as Built In Security Mechanism.

Development Tools and Support:

Microsoft developed Visual Studio tool. It not only makes the development faster but also easy. It saves time of common configuration of our application. We can Create Manage, Design and Handle our project at single place.
We also get Debug, Error Handling, Packaging and Deployment help at single place.

1.3 Platform Programming:

.Net is multi language platform and more than 50 languages which have be designed or modified to support CLS specification of Dot Net framework. Microsoft support mainly four programming languages:

C# (C Sharp):

This programming language is top choice of developed. MS officially backed C# for development in .Net framework. C# is powerful like JAVA and retain powerful concepts from other languages such as C and C++ also.

VB.NET :

Visual Basic .Net is advanced version of VB 6.  OOPs concepts were lacking in VB 6 so MS added OOPs support to VB.NET. At present, marking share of VB.Net is reducing. Many developers and companies are leaning towards C#.

C++ /CLI (Common Language Infrastructure):

This is only Managed Code Extension of C++ programming. It enables us to design Dot Net framework based application by using C++ code syntax.

F# :

F# language is mainly for Financial and Scientific computing. Programmers use this language as Functional Programming.  Though very few people use F# and Microsoft only concentrating C#.
Apart from these languages, COBOL, Small Talk , Pascal, APL and Delhi are also used to develop application on  .Net framework.

Code Execution Process in Dot Net Platform:

There are two Code Execution processes:
 1.  Compile Time Process:
In this stage, the source code of our application is converted into intermediate code called MSIL (Microsoft Intermediate Language) or simply IL(Intermediate Language). Now a days, it is also known as CIL (Common Intermediate Language) .  MSIL code is not machine dependent code. So we can’t execute on any system directly.

Source Code à .Net Compiler à Byte Code (MSIL + META DATA)
2.   Run Time Process:
In the Run Time Stage, MSIL code is converted into machine code which is done by CLR (Common Language Runtime). CLR is heart of .Net framework. CLR includes Garbage Collection (GC), Code Access Security (CAS) , Code Verification (CV) and Just In Time (JIT) . JIT compiler actually does the IL to Native translation.

Byte Code (MSIL + META DATA) à JIT à Native Code
Native code is fully compatible with machine.
Please view below images to understand Code Execution Process.
Since MS support multiple languages for .Net framework, so there may be a situation when one type defined in a language may differs with type of another one. Every language must follow these types to make them compatible with .Net Framework:
1.       Value Type
2.       Reference Type
3.       Pointer Type

1.4 Development Environment Setup:

Every Programming Language is learnt by practicing small and fundamental programs. So we need any text editor or IDE. Text editors can be used for practice of small programme but developing whole project is very hard task. That’s why we use IDE (Integrated Development Environment). IDE makes development faster as they include useful tools. Build in support of such tool makes development, debugging and deployment easy.

For Development in .Net Framework using C#, we will use IDE. There are some commercial and free Tools we can use for this purpose. For example:
1.       Visual C# Express Edition
2.       Visual Studio Ultimate or Similar Commercial Version
3.       SharpDevelop
Using IDE at beginner level is not recommended as we may not be aware what’s happening. If you really want to understand basic code structure and working, I recommend use text editor such as NotePad ++ (NPP).
To use NPP as default C# IDE , you must download and install two plugins , “Explorer” and “NppExec” from plugin manager.
Please search “Using NotePad ++ for C # Development” in Google for more help.
Setting Visual Studio for development in C# is easy. You must set C# as default language. Follow on screen command during installation. If you find any difficulties, please let me know. I will use VS 10 edition’s screenshot in this tutorial.



Read More

Blogger