Sie sind auf Seite 1von 42

Welcome to C# Training

Mathi B.Tech., M.E


IFY TECHNOLOGIES,
Tirunelveli.

.NET Framework

Introduction to C#
C# (pronounced "C-sharp") is an object-oriented programming
language from Microsoft that aims to combine the computing power
of C++ with the programming ease of Visual Basic.
C# is based on C++ and contains features similar to those of
Java. C# is designed to work with Microsoft's .NET platform.
Developed by Anders Hejlsberg(Microsoft).from Denmark.
Based on Java and C++, but has many additional extensions.

Cont
Cross-development with Visual Basic, Visual C++, F#, IronPython,
and many other .NET languages.
C# syntax derived from C++ and java.
The basic syntax of C# comes from C++.Where structure is inherited
from java.
Just like virtual machine for java. The .NET CLR can provide many
features including automatic memory management and garbage
collection.

Overview
The following reasons make C# a widely used professional
language:
Modern, general-purpose programming language.
Object oriented.
Easy to learn.
Structured language.
Produces efficient programs.
Part of .NET Framework

Objective & Features of C#


Its simple and object oriented programming
languages.
Its useful for developing software
components.
This provide a support for software
engineering principles.

Why C#
It has been designed to support the key feature of .NET framework.
It is great language for programming as it offers several key benefits for
programmers.
They are,
Simplicity
consistency
Flexibility
modernity
object orientation
Scalability
Various support

C# console based application


Hello World - Your First Program
In order to create a C# console based application.
Open your Visual Studio
On the File menu, click New Project.
Then the New Project dialog box appears. This dialog box lists the different
default application types.
Select Console Application as your project type and change the name of
your application at the bottom textbox.
If you are not comfortable with default location, you can always enter a new
path if you want.
Then Click OK.
After click OK button, you will get a screen like the following picture.

In this session
Basic structure of a c# program.
What is a Namespace.
Purpose of Main method.

Simple Program

Program Explanation
The first line of the program using System; - the using keyword is used to include
the System namespace in the program. A program generally has multiple using
statements.
The next line has the namespace declaration. A namespace is a collection of
classes. A namespace is used to organize your code.
The HelloWorldApplication namespace contains the class HelloWorld.
The next line has a class declaration, the class HelloWorld contains the data and
method definitions that your program uses. Classes generally contain multiple
methods. Methods define the behavior of the class. However, the HelloWorld class
has only one method Main.
Main method is the entry point into your application.

Sample program

Reading and Writing to Console

Sample pgm (Read & write)


using System;
class Program
{
static void Main(string[] args)
{
//Prompt the user for his name
Console.WriteLine("Please enter your name");
//Read the name from console
string Username = Console.ReadLine();
//Concatenate name with hello word and print
Console.WriteLine("Hello" + Username);
//Placeholder syntax to print name with hello word
//Console.WriteLine("Hello{0}",Username);
}}

Arithmetic operator

Comparison operator

Output

Conditional operator(And)

Conditional operator(OR)

Ternary operator without use

Ternary use

How to use C# for loop


For loop:
A for loop is a repetition control structure that allows you to efficiently write a
loop that needs to execute a specific number of times.
Syntax:
for ( init; condition; increment )
{
statement(s);
}

Example:
for (int a = 10; a < 20; a = a + 1)
{
Statements(s);
}

Flow chart(For Loop)

How to use C# while loop


while loop:
The while statement continually executes a block of
statements until a specified expression evaluates to false .
Syntax:
while(condition)
{
statement(s);
}

Flow chart(while loop)

Constructor
It is a special type of method which has a same name as of a class
name generally it is used to initialize a value for a variable.

Uses
Constructors enable the programmer to set default values,and
write code that is flexible and easy to read.

Rules
Constructor should have a same name has
of a class name.
Constructor will not have a return type.

Destructor
It is a special type of method which has a
same name as a class name. Which will
precide with(~)tilled symbol.
Uses:
It is used to deallocate the memory of the
variable.

C# windows based application

Output

Das könnte Ihnen auch gefallen