11-12-2010
Switch Condition: Whenever we want to execute one case among multiple cases then we can implement a switch condition.
Synatx: Switch(<Expression>)
{
case 0:
statement 1;
break;
case 1:
statement 2;
break;
case 2:
statement 3;
break;
default:
statement 4;
break;
}
Eg: for Switch Condition:
void main()
{
Console.WriteLine(" Enter current month number ");
int number = Convert.ToInt32(Console.ReadLine());
switch(month)
{
case 1:
Console.ReadLine();
}
Loops: Whenever we want to execute a single statement (or) multiple statements, multiple times based on some conditions we will implement loops.
We can implement four types of loops. They are:
for(<initialization>:<condition> ++/--)
Void main()
{
for(int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
2. While loop: Syntax:
While(<condition>)
{
statement 1;
statement 2;
++/--
}
Ex: While loop:
Void main()
{
int i = 1;
While( i <= 10)
{
Console.WriteLine(i +" ");
i++;
}
Console.ReadLine();
}
Write(): Write is a predefined member of console class. This method will print the given value on command prompt window after printing the value it will not move the cursor to next line it will keep the cursor in the same line to print next value.
Class Console
{
Write()
{
}
}
Iteration: Executing a block of statements in one time can be called as one itteration.
3. Do while loop:
Syntax:
Void main()
{
int i= 1;
Do
{
console.write(i +" ");
i++;
}
While(i <= 10);
Console.ReadLine();
}
Data Types: Every programming language will have its own data type, similarly every .Net language will have its own data types.
Data types specifies the types of the data and size of the data.
According to type of the data and size of the data C#.Net data types are classified into five types.
1. Numerical data types.
2. Floating Point.
3. Character related data types.
4. Logical data types.
5. General data types.
Which can be called as primitive data types.
Above 1, 2, 3, 4 data types are having the predefined sizes but 5th data type is not having the predefined size that means general data type is not having the pre-defined sizes that means pre-defined sizes.
Synatx: Switch(<Expression>)
{
case 0:
statement 1;
break;
case 1:
statement 2;
break;
case 2:
statement 3;
break;
default:
statement 4;
break;
}
Eg: for Switch Condition:
void main()
{
Console.WriteLine(" Enter current month number ");
int number = Convert.ToInt32(Console.ReadLine());
switch(month)
{
case 1:
Console.WriteLine("January");}
break;
case 2:
Console.WriteLine("February");
break;
case 3:
Console.WriteLine("March");
break;
case 4:
Console.WriteLine("April");
break;
case 5:
Console.WriteLine("May");
break;
case 6:
Console.WriteLine("June");
break;
case 7:
Console.WriteLine("July");
break;
case 8:
Console.WriteLine("August");
break;
case 9:
Console.WriteLine("September");
break;
case 10:
Console.WriteLine("October");
break;
case 11:
Console.WriteLine("November");
break;
case 12:
Console.WriteLine("December");
break;
default:
Console.WriteLine("Invalid Month");
break;
Console.ReadLine();
}
Loops: Whenever we want to execute a single statement (or) multiple statements, multiple times based on some conditions we will implement loops.
We can implement four types of loops. They are:
1. For loop1. For loop: Syntax:
2. For each loop
3. While loop
4. Dowhile loop
for(<initialization>:<condition> ++/--)
{Ex: For loop:
statement 1;
statement 2;
}
Void main()
{
for(int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
2. While loop: Syntax:
While(<condition>)
{
statement 1;
statement 2;
++/--
}
Ex: While loop:
Void main()
{
int i = 1;
While( i <= 10)
{
Console.WriteLine(i +" ");
i++;
}
Console.ReadLine();
}
Write(): Write is a predefined member of console class. This method will print the given value on command prompt window after printing the value it will not move the cursor to next line it will keep the cursor in the same line to print next value.
Class Console
{
Write()
{
}
}
Iteration: Executing a block of statements in one time can be called as one itteration.
3. Do while loop:
Syntax:
DoEg: Do while:
{
Statement 1;
Statement 1;
++/--
}
while(<condition>);
Void main()
{
int i= 1;
Do
{
console.write(i +" ");
i++;
}
While(i <= 10);
Console.ReadLine();
}
Data Types: Every programming language will have its own data type, similarly every .Net language will have its own data types.
Data types specifies the types of the data and size of the data.
According to type of the data and size of the data C#.Net data types are classified into five types.
1. Numerical data types.
2. Floating Point.
3. Character related data types.
4. Logical data types.
5. General data types.
Which can be called as primitive data types.
Above 1, 2, 3, 4 data types are having the predefined sizes but 5th data type is not having the predefined size that means general data type is not having the pre-defined sizes that means pre-defined sizes.