Vous êtes sur la page 1sur 25

1

2
Overview
Getting Started -Structured to OOPs, Advantage of OOPS
C# features
Expression ,Data types & Variables
Control Statements - Selection
Control Statements - loop
Methods
3
Why Structured programming to OOPs?

Structured Programming:
Based on Data structures and Subroutine.
Source code divided into logically structured blocks
Consist of Conditional statements, loops and logic blocks.
Object oriented Programming:
Each program is made up of many entities called objects.
Process of using several classes to represent different areas of functionality.



4
Structured programming Object oriented Programming
Structure the program into hierarchy of
sub program
Break down the program task into
object,
which encapsulate data and methods.
Flexibility is less Flexibility is more
Even structure program provides
clarity, a small change want to change
the total subroutine program
But here the class is used so changes
can be made easy
Task Centric Data Centric
Examples: ALGOL, Pascal, COBOL, Ada
and PL/I

Examples: Objective C, C++, C#, Java and
FORTRAN
5

The advantages of OOPs are:

1. Simplicity


2. Modularity


3. Modifiability


4. Extensibility


5. Maintainability


6. Re-usability


6

Object Oriented Programming techniques will include features such as:

Data abstraction

Encapsulation

Messaging

Modularity

Polymorphism

Inheritance





7
C # Features
C# 1.0
Microsoft Released the 1
st
version of C# with Visual studio 2002.
Use of Managed code
C# 2.0
Second version of Csharp with Visual studio 2005.
New features are there, which helps in coding the applications in a Generic Way.
*Generics-Used with collections and methods
*Anonymous methods-Define code block where delegate object is acceptable.
*NullType-Represents the correct range of values for its underlying value type +
additional Null value.
*partial class-We can split a single class/struct/interface into 2 to many, which can
be combined at the time of compiling.



8
*Covariance- substitute Derived types into Base Types.
*Contravariance- substitute Base types into Derived Types.
C# 3.0
*Lamda Expression-Allow functions to be used as data such as variables or
fields.
*Extension method- allows to extend the existing type with new function with
out having Subclass/Recompiling.
*Expression Tree- Represents the code in the form of tree like a Data structure ,
where each node is a expression.
C# 3.5
LINQ-Language integrated Query
Helps in accessing data from different repositories, like Memory objects,Data
bases,XML files.



9
C# 4.0
*Developed with Visual studio 2010.
* Makes use of Dynamic Language run Time(DLR)
Features are,
*Optional Parameters-Optional arguments enable you to omit arguments for
some parameters.
*Named Arguments-Named arguments enable you to specify an argument for a
particular parameter by associating the argument with the parameter's name
rather than with the parameter's position in the parameter list.
* Generic variance
*COM interoperability-
* Interaction with COM components from .NET
* Interaction with .NET components from COM
10
Expressions,DataType,Variables

Definition:
EXPRESSION:
An expression is a mixture of values, operations of
expressions and function calls that can be evaluated to a
value.
VARIABLE:
Variable is a storage location.

DATA TYPE:
Data Types in a programming language describes that what type
of data a variable can hold .
11
Expression and Datatype

Expressions: in EVERY LANGUAGE are built from combinations of operators
and operands,
example :x = a+b*(-c)
Datatypes:
Syntax : DataType VariableName
DataType : The type of data that the variable can hold
VariableName : the variable we declare for hold the values.
Example:
int count;
int : is the data type
count : is the variable name
12
Types of data type

PRIMITIVE DATATYPE (Built in)

(int,float,double,long int,short int,signed int,unsigned int,char,string,bool)

NON PRIMITIVE DATATYPE (user defined)

(class,struct)
13
Control Statement
14
Control Statement - Selection
15
Control Statement - Selection
16
Control Statement - Selection
17
while loop
It is an entry-check loop
Syntax: Ex:
while(<condition>) int x = 1;
{ while(x <= 10)
Action Block; {
} console.writeLine(x);
x++;
}



Console.WriteLine(x);
X++;
}

while(<condition>)
{
action block;
}

18
do while

It is an exit check loop. Ex:
Syntax: no=0;
do do
{ {
action block; Console.WriteLine(no);
while(<condition>); no=no+1;
} }while(no<5);


19
for

for(initial value; test condition ; increment)
{
action block;
}
It works like a while loop.

Ex: for(int x = 1; x <= 10; x++)
{
Console.WriteLine(x);
}
20
foreach
operates on collections of items, for instance arrays or other built-in list
types.
Syntax:
foreach(<string values>)
{
action block;
}
string[] names = {"Cheryl", "Joe", "Matt", "Robert"};

foreach (string person in names)
{
Console.WriteLine("{0} ", person);
}


21
break and continue
break will exit the loop completely, continue will just stop the current iteration.
Ex:
for( int i =0 ; i < 20 ; i++)
{
if(i ==0)
break;
if(i%2==0)
continue;
}

22
Methods
Definition:
A method is a code block containing a series of statements. Methods are
declared within a Class or Struct by specifying the access level, the return
value, the name of the method, and any method parameters. Method parameters
are surrounded by parentheses, and separated by commas.
Syntax:
[ modifiers] [return-type] [method-name](parameters )
{
statements
}
Example:
Class motor
{
public void startengine()
}
Calling a Method:
motor motorobject = new motor();


23
Passing parameters to methods
Call by value
In call by value method, the
called function creates a new set of
variables and copies the values of
arguments into them.



Call by reference
In call by reference method, instead
of passing a value to the function
being called a reference/pointer to the
original variable is passed.


24
Special Methods
Delegates:
A delegate is a type that references a method. Once a delegate is assigned
a method, it behaves exactly like that method.

Example:
public delegate int PerformCalculation(int x, int y);
Anonymous method:
An anonymous method is a method without any name.
Advantage of delegates.
Example:
// Instantiate the delegate type using an anonymous method:
Printer p = delegate(string j)


25
Thank You

Vous aimerez peut-être aussi