C# For Beginners
Chapter – I
About .NET AllAbout Microsoft. NET
.NET Framework Process
Terms Associated with Microsoft. NET
Chapter – II
Begin C-sharp Introduction
Basic Requirements to begin C# Programming
Chapter – III
Your First C# Program Getting Started with Hello C-Sharp
CHAPTER – 1 : About icrosoft. NET
Microsoft. NET is one of the latest and newtechnologies introduced by Microsoft
Corporation. Nowadays we use to connect to the internet using a computer
and a remote computer responses via a web page and a collection of web pages
are called as Web Sites. The Concept in .NET is that these websites can
integrate with other sites and services using Standard Protocols like HTTP.
Microsoft .NET Platform comprises of four core components such as
- .NET Building Block Services such as file storage, calendar called Passport. NET
- .NET Device Software which will run on latest Internet Devices like MobilePhones.
- .NET user experience such as integrating this technology to user created
documents (integrates with XML). For example if you code
XML via a .NET Language like C#, it will automatically createXML document
- .NET infrastructure which includes
.NET Framework (Common Language Runtime & .NET Framework Class Libraries)
Microsoft Visual Studio.NET such as Visual Basic.NET ,Visual C++.NET etc
.NET Enterprise Servers and Microsoft Windows. NET
We can build robust, scalable,distributed applications with the help of .NET
and the part that helps us to develop these applications is called the .NETFramework.
The .NET Framework contains Common Language Runtime (CLR) and the
.NET Framework class libraries also called as Base Class Libraries.
All the .NET languages (like C-sharp, VisualBasic.NET, Visual C++. NET etc) have
the .NET Framework class libraries built into them. The .NET class Librariesalso supports
File I/O, database operations, XML (Extensible Markup Language) and
SOAP (Simple Object Access Protocol). For example you can develop XML Pages
by using C-sharp language.
When someone talks about .NET development, then you should understand that theyare talking
about .NET Framework. It includes a Runtime environment and a set of ClassLibraries which is
being used by a new language called C-sharp abbreviated as C#
(more or less similar to C/C++/Java family of languages) and all other.NET Languages.
Simply speaking C-sharp is a new language for developing custom solutions for Microsoft's.NET Platform.
The runtime which we discussed just now is also used by VisualStudio.NET.
Visual Studio.NET Provides us with a visual environment to design and develop.NET Applications.
Every language in VisualStudio.NET uses this runtime to execute itsapplications.
Moreover these languages compiles its source code into an intermediatelanguage upon compilation.
Hence you can very well use a module written using C-sharp in a Visual BasicApplication.
For example you can design a user interface with Visual Basic.NET and write aDLL function using C-sharp.

Terms Associated withMicrosoft .NET
| Common Language Runtime |
| Common Language Runtime also called CLR Provides a universal execution engine for developers code. It generates SOAP when it makes remote procedure calls. CLR is independent and is provided as part of the .NET Framework. The main features of CLR are as follows (1) Managed Code (2) Automatic application installation (3) Memory Management (4) Automatic Garbage Collection (5) Very high level of Security while executing |
| .NET Framework Class Libraries |
| These class libraries works with any language under the common language runtime environment. It includes Visual Studio.NET, C-Sharp. Therefore if you are familiar with one .NET language then you can easily migrate to other .NET Languages. The figure given below shows the .NET Framework hierarchy |
![]() |
| Note: - 1. All namespaces should have to be called in your Program by applying the keyword using. For example if your programs needs to call System namespace, then it should be applied in the program as using System. 2. Classes cannot be called along with the using directive. 3. The using directive applies only to namespaces, just like importing |
| Common Language Specification (CLS) |
| You should note that the syntaxes and other programming structures differ from each of these languages. The only difference is that a developer well versed with a language such as C-sharp can easily program in Visual Basic.NET or Visual C++.NET without investing a lot or spending too long to learn a new language. |
CHAPTER – 2: Begin C-Sharp Programming
First of all let me welcome you to the world ofthis new programming language.
I hope you will have a basic idea about Object Oriented Programming languagesbecause
many languages like Java, C++ have come by the past 5 years.Howeverthere will be no
difficulty in learning this language if you are a fresher, because this tutorialand the
coming ones will explain all the concepts and features right from the beginning.
Wherever required I explained the features involved in C-sharp by comparing themwith Java.
This will ensure smooth progress for experienced Programmers.
I recommend you to install the appropriate software's outlined in the nextsection
before learning this new language.
BasicRequirements needed to begin C-sharp Programming
1 .NET Framework Software Development Kit and
2 An Editor (like Notepad or DOS Editor) to write source codes.
Optional Requirements: -
1. Visual C#. NET or
2. Visual C++ 6.0 included with VisualStudio 6.0
Installing .NET Framework SDK
As a first step you should install .NET SDK on your computer to begin C-sharpProgramming.
It can be downloaded from the Microsoft's Website. It is also available withalmost all the
popular computing magazine CD'S. It also comes with the complete documentation
in the form of HTML Help.
At the time of this writing only beta version of the kit is available. This kitenables you to
compile & execute the source code in C#, Visual Basic by using its built-in
Command line Compiler (csc and vbc) and runtime Just In Time (JIT) Compiler.
This is similar to Java Compiler (javac) and Java Interpreter (java) included
with Java Development Kit.
You can also develop applications with C-sharp and Visual Basic by using VisualStudio.NET
languages like Visual C#.NET and Visual Basic.NET. This will help you to developwindows based
applications easily and with limited effort because you don't have to devote toomuch
time in designing the user interface (Usage of WinForms).
The only work left for you to do is to write the codings appropriately as perthe .NET Standards.
About the Editors
Notepad is the best choice among developers using .NET SDK todevelop C# applications.
However it is not the most suitable editor since it does not support syntaxcoloring, code numberings etc.
Developers can use Visual C++ 6.0 included with Visual Studio 6.0.However they
should make some tweaking in the registry before using the same. It supportssyntax colorings
and other features such as finding line numbers (Ctrl+G). However it isdangerous for a new user
to make changes in registry. Hence only advanced and experienced users can beable to use
Visual Studio 6.0 for developing C#. It is not possible to compile and execute
the applications from the Visual C++ 6.0 Environment.
Hence there is not much use except some of the features listed above.
VisualStudio.NET provides all the integrated tools and wizards forcreating C# and
Visual Basic applications. It also supports features such as intellisense,Dynamic help.
Moreover you can compile and execute your applications from the IDE itself.
Hence in order to experience the power of developing the .NET
applications, you should try VisualStudio.NET.
Many Third Party editors are now available either from magazine'sCD'S or
can be downloaded from the internet. However it is up to you to decide
upon which editor to use. I recommend you to try one common
editor and learn the language in full.
CHAPTER – 3: Your First Hello C# Program
GettingStarted with Hello C-Sharp
After understanding the fundamentals of .NET and itsStructure, let us now move on to
look at a classic Hello C# Program. As I mentioned in the previous tutorial, youcan
use any text editor as per your Convenience.
Listing 3.1 gives the coding for this simple Hello C# Program.
<textarea style="background-color: #ffcc66;" name="S1" rows="4" cols="67">Using System ; Class Hello { Public static void Main () { Console.writeLine ("Hello C#"); } } //end of the main</textarea>
What to do next: -
- Save the following file as Hello.cs.cs is an extension to indicate C-sharp
like .java for a Java Source File. You have to supply thisextension while saving
your file, otherwise the code will not compile correctly. The savedfile will be of
.cs.txt extension.
- Compile the above Code by giving the following Command at the
Command Prompt csc Hello.cs
- If there are compile errors then you will be prompted accordingly, otherwise you
will be getting a command prompt with the copyright information.Keep in mind
that the compiler generates MSIL.
- Your next job is to execute the program to view the final Output. For thatpurpose
you have to simply give Hello at the command Prompt. Ifeverything goes on well,
a message Hello C# will be printed on the Screen.
You can view the MSIL Code generated by any .NETLanguage with the help of an Utility
called Intermediate Language Disassembler or shortly ILDASM. This utilitywill display
the application's information in a tree like fashion. Since the contents of thisfile is
read only, a Programmer or anybody accessing these files cannot make any
modifications to the output generated by the Source Code.
To view the MSIL Code for the above Hello C# Program, open Hello.exe file from
the ILDASM tool. In Windows 98, ME & NT this tool can be accessed via
start – programs – Microsoft .NET Framework SDK – Tools – IL Disassembler
Detailed Review of theabove Program: -
I am giving below the process occurring to the sourcecode, during the compilation and
execution stages once again for your reference.
Com
pilation Stage: -
C# Compiler produces MSIL as output after compilation. It is itself acomplete language
and it is more or less similar to Assembly language. MSIL stands for MicrosoftIntermediate Language.
The same thing happens to any application written in any CLR Compliant
Language like Visual Basic.NET, Visual C++.NET etc.
Execution Stage: -
The MSIL is then compiled into native CPU instructions by using JIT (Just inTime) compiler
at the time of the program execution. The Source Code is recompiled and
executed only after making any changes to it .
Now let us analyze the Hello C# Program as a whole. Iam giving below the code
once again for your reference. Please note that the line numbers are given forclarification
and explanation and is not a part of the Source Code.
<textarea style="background-color: #ffcc66;" name="S1" rows="4" cols="67">1 using System ;2 class Hello {3 public static void Main () {4 Console.writeLine ("Hello C#"); 5 } 6 } //end of the main</textarea>
Line Number wise Analysis
Line 1: – It is called as the namespace. Simply speaking, a namespace is a collection of .NET Classes similar to packages in Java.
Line 2: It is the class declaration similar to Java & C++
Line 3: – This is the main method which is required in all C# applications
Line 4: – This code will print Hello C# onto the Console. Here Console is the class belonging to System namespace and writeLine is the static method belonging to Console Class.
Line 5:- The Opening and Closing curly races are similar to that of C++/Java.




18. Feb, 2006 by 








No comments yet... Be the first to leave a reply!