Sie sind auf Seite 1von 3

C#.

NET
Introduction

 C#.Net (pronounced “see sharp”) is simple, modern, general-purpose, object-oriented


programming language.
 C #.Net language is developed by Microsoft.
 C#.Net is a language derived from c++ and java.
 C#.Net is a Case Sensitive language.
 C#.Net is a strongly typed language.
 All the .Net base classes were written in C#.Net.

C#.Net language Features

 There are various features provided by c#.Net language.


 C#.net supports various pre processer directives.
 C#.net is an object oriented programming language, so it will support the object
oriented concepts like classes, object, inheritance, polymorphism, etc….
 C#.Net supports garbage collection, automatic memory management.
 C#.net does not support pointer usage in managed code (handled by CLR).it will be
handled as unsafe code where there is no interference of CLR.
 C#.net supports structures, which are similar like classes.
 C#.net supports assemblies which are self describing units. An assembly solves all the
COM and “dll” problems.
 There are no global variables in c#.Net.
 C#.net supports event handling mechanism using delegates (function pointers).
 C#.Net 2.0 features
o Generics
o Partial classes
o Anonymous Methods
o Static classes
o Pragma directive
o Nullable types
 C#.Net 3.0 features
o LINQ (Language Integrated Query).
o Type Interference.
o Anonymous Types
o Lambda Expressions.
 C#.Net 3.5 features
o Automatic properties.
o Object and Collection Initializers
o Extension Methods.
o Implicitly Typed Local Variables

C#.Net versions list

Version Year Language Feature


1.0 2002 Basic language Features
1.1 2003 ------
2.0 2005 Generics, partial classes, Anonymous methods,
Iterators, static classes
3.0 2006 LINQ, LambdaExpressions, Anonymous types
3.5 2008 Implicit Local variables, Extension Methods,
partial methods

N.N.V.Raj Gopal , lecturer in Dept of ComputerScience,T.J.P.S College(PG Courses),GUNTUR. 1


Applications of C#.NET:
 There are various types of application can be developed using c#.net.
 Console Application
 Windows Application
 Windows services
 Web Application
 Web Services
 Mobile Applications
Sample Program in C#.Net

Save the Program : D:\first.cs


Compile the program : D:\> csc first.cs
Run the program : D:\> first

1) class is a c# keyword which represents a class in c#, which is followed with


the Curly braces indicates starting and ending of the class

2) first is the class name which is used to access class members.

3) public is an Access modifier indicates the Main() method can be accessed from
the outside of the class.

4) static keyword allows the Main() method to be executed without creating an


object of that class.

5) void keyword represents Main() method does not return a value.

6) Main is a keyword, which tells the compiler it is the entry point and exit point
for the program. There are various types of Main() method signatures
Ex: public static void Main(String[] args)
public static void Main()
public static int Main() //if it returns Integer value

7) (String [] args) is a command line arguments, which are passes during


program execution. “args” is a string array which stores string elements
passed during runtime.

8) System is a predefined Namespace available in C#.Net.


9) Console is a class in the System namespace. it contains various methods to
perform Console based input and output operations.

10)WriteLine() method is used to Write information on the console window.

N.N.V.Raj Gopal , lecturer in Dept of ComputerScience,T.J.P.S College(PG Courses),GUNTUR. 2


3 Styles of Executing C#.Net Program

 Style-1)Notepad with O.S command prompt


o Open notepad and type the C# program in the editor.
o Save the file with “.cs” extension like as “D:\first.cs”.
o Search for csc.exe in the c: drive using search tool in start menu
o Open O.S. Command prompt and move to D: drive
o Set path to the csc.exe compiler as given below
D:\> set path= “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727”
o Compile the program using “csc” c# compiler.
D:\> csc first.cs
o Run the program
D:\> first
 Style-2)Notepad with Visual Studio Command prompt
o Open notepad and type the C# program in the editor.
o Save the file with “.cs” extension like as “D:\first.cs”.
o Open Visual Studio Command prompt and move to D: drive
Start  programsVisual studio 2005visual studio tools
Visual studio 2005 command prompt
o Compile the program using “csc” c# compiler.
D:\> csc first.cs
o Run the program
D:\> first
 Style-3)Visual Studio.Net Editor
o Open visual studio.net editor
Start programs Microsoft visual studio.net 2005
 Microsoft visual studio.net 2005
o Go to File menu New  project
o Select the language and the project name, type and location as given below
Language : Visual c#
Project Type : Console Application
Project Name : First
Location : D:\MyExamples
o Go to solution Explorer window , select program.cs file
o Type the program in code window
o Compile the program (shortcut F6)
Go to  Build menu  Build solution
o Run the program (shortcut F5)
Go to  Debug menu  start debugging
Comments in c#.Net
 There are two types of comment statement in c#.Net. They are
1. Single line Comments (//)
2. Multi line Comments (/* and */)
 Single line Comments uses double slash “//” symbol to begin a comment and it ends
at the end of the line.
Ex: int a=10; //assaign 10 to a
Book b=new Book (); //creates an Object for Book class.
 Multi line Comments are applied to multiple line of code, where it starts with “/*”
and ends with “*/”
Ex: /*
Statement-1

Statement-n
*/
N.N.V.Raj Gopal , lecturer in Dept of ComputerScience,T.J.P.S College(PG Courses),GUNTUR. 3