SlideShare a Scribd company logo
unit 1 (1).pptx
 C# (pronounced "C sharp") is a simple, modern, object-
oriented, and type-safe programming language.
 C# combines the high productivity of Rapid
Application Development (RAD) languages and the
raw power of C++
 Visual C# .NET is Microsoft's C# development tool
 It includes an interactive development environment,
visual designers for building Windows and Web
applications.
 Visual C# .NET is part of a suite of products,
called Visual Studio .NET, that also includes
Visual Basic .NET, Visual C++ .NET, and the
Jscript scripting language.
 All of these languages provide access to the
Microsoft .NET Framework, which includes a
common execution engine and a rich class
library
 It is a modern, general-purpose
programming language
 It is object oriented.
 It is component oriented.
 It is easy to learn.
 It is a structured language.
 It produces efficient programs.
 It can be compiled on a variety of computer
platforms.
 It is a part of .Net Framework.
 Like c++, both single and multiline comments supports
 C# builds on the
◦ High performance [c]
◦ Object oriented structure ( c++)
◦ Security ( java)
◦ Rapid development ( visual basic)
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
/* my first program in C# */
Console.WriteLine("Hello World");
}
}
OUTPUT
Hello,world
 The source code for a C# program is typically
stored in one or more text files with a file
extension of .cs, as in hello.cs.
 The source code for a C# program is typically
stored in one or more text files with a file
extension of .cs, as in hello.cs.
unit 1 (1).pptx
 using System- directive references a
namespace called System that is provided by
the Microsoft .NET Framework class library.
 A variable is nothing but a name given to a
storage area that our programs can
manipulate.
 Each variable in C# has a specific type, which
determines the size and layout of the
variable's memory the range of values that
can be stored within that memory and the set
of operations that can be applied to the
variable.
Type Example
Integral types sbyte, byte, short, ushort, int, uint,
long, ulong, and char
Floating point
types
float and double
Decimal types decimal
Boolean types true or false values, as assigned
Nullable types Nullable data types
Syntax for variable
<data_type> <variable_list>;
Example
int i, j, k;
char c, ch;
float f, salary;
double d;
Initializing Variables
syntax
<data_type> <variable_name> = value;
Example
int d = 3, f = 5;
double pi = 3.14159;
char x = 'x';
using System;
namespace VariableDefinition
{
class Program
{
static void Main(string[] args)
{
short a;
int b ;
double c;
a = 10;
b = 20;
c = a + b;
Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
Console.ReadLine();
}
Output:
a = 10, b = 20, c = 30
Example
int num;
num = Convert.ToInt32(Console.ReadLine());
 The function Convert.ToInt32() converts the data
entered by the user to int data type,because
Console.ReadLine() accepts the data in string format.
 lvalue: An expression that is an lvalue may appear as
either the left-hand or
 right-hand side of an assignment.
 rvalue: An expression that is an rvalue may appear on
the right- but not lefthand side of an assignment.
 Variables are lvalues and hence they may appear on
the left-hand side of an assignment. Numeric literals
are rvalues and hence they may not be assigned and
can not appear on the left-hand side
Single-line Comments
 Single-line comments start with two forward
slashes (//).
Example
// This is a comment
Console.WriteLine("Hello World!");
C# Multi-line Comments
 Multi-line comments start with /* and ends
with */.
data type specifies the size and type of
variable values.
 Value types
 Reference types
 Pointer types
Data Type Size Description
int 4 bytes Stores whole numbers from -2,147,483,648 to
2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7
decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal
digits
bool 1 bit Stores true or false values
char 2 bytes Stores a single character/letter, surrounded by single quotes
string 2 bytes per
character
Stores a sequence of characters, surrounded by double q
 Value type variables can be assigned a value
directly
 They are derived from the class
System.ValueType.
 The value types directly contain data
 examples are int, char, and float, which
stores numbers, alphabets, and floating point
numbers, respectively.
 The system allocates memory to store the
value
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int myNum = 100000;
Console.WriteLine(myNum);
}
}
}
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
long myNum = 15000000000L;
Console.WriteLine(myNum);
}
}
}
Output
15000000000
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
float myNum = 5.75F;
Console.WriteLine(myNum);
}
}
}
Output
5.75
 Use float or double
 The precision of a floating point value
indicates how many digits the value can have
after the decimal point. The precision
of float is only six or seven decimal digits,
while double variables have a precision of
about 15 digits. Therefore it is safer to
use double for most calculations.
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
double myNum = 19.99D;
Console.WriteLine(myNum);
}
}
}
Output
19.99
A floating point number can also be a scientific number with an "e" to
indicate the power of 10:
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
float f1 = 35e3F;
double d1 = 12E4D;
Console.WriteLine(f1);
Console.WriteLine(d1);
}
}
}
Output
35000
120000
 The reference types do not contain the actual
data stored in a variable, but they contain a
reference to the variables.
 they refer to a memory location
 Using multiple variables, the reference types
can refer to a memory location.
 If the data in the memory location is changed
by one of the variables, the other variable
automatically reflects this change in value.
 Example- object,dynamic, and string
 The Object Type is the ultimate base class for all data
types in C# Common Type System (CTS).
 The object types can be assigned values of any other
types, value types, reference types, predefined or
userdefined types.
 However, before assigning values, it needs type
conversion
 When a value type is converted to object type, it is
called boxing
 when an object type is converted to a value type, it is
called unboxing
object obj;
obj = 100; // this is boxing
Int b=(int)obj//unboxing
 We can store any type of value in the dynamic data
type variable.
 Type checking for these types of variables takes place
at run-time.
 Syntax
 dynamic <variable_name> = value;
 example
 dynamic d = 20;
 Dynamic types are similar to object types except that
type checking for object type
 variables takes place at compile time, whereas that
for the dynamic type variables takes place at run
time.
 String Type
 The String Type allows you to assign any
string values to a variable
 The string type is an alias for the
System.String class.
Example
String str = "Adithya Institute of Technology";
 Pointer type variables store the memory
address of another type.
 Pointers in C# have the same capabilities as
the pointers in C or C++.
 Syntax
 type* identifier;
 example
 char* cptr;
 int* iptr;
 Implicit Casting (automatically) - converting a
smaller type to a larger type size
char -> int -> long -> float -> double
 Explicit Casting (manually) - converting a
larger type to a smaller size type
double -> float -> long -> int -> char
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to
double
Console.WriteLine(myInt);
Console.WriteLine(myDouble);
}
}
}
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
double myDouble = 9.78;
int myInt = (int) myDouble; // Manual casting: double to int
Console.WriteLine(myDouble);
Console.WriteLine(myInt);
}
}
}
 1. Arithmetic Operators
 2. Relational Operators
 3. Logical Operators
 4. Bitwise Operators
 5. Assignment Operators
 6. Misc Operators
Operator Name Description Example
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
++ Increment Increases the value of a variable by 1 x++
-- Decrement Decreases the value of a variable by 1 x--
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int x = 5;
int y = 2;
Console.WriteLine(x+y);
Console.WriteLine(x-y);
Console.WriteLine(x*y);
Console.WriteLine(x/y);
Console.WriteLine(x % y);
Console.WriteLine(x++);
Console.WriteLine(x--);
}
}
}
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
unit 1 (1).pptx
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int x = 5;
int y = 3;
Console.WriteLine(x == y);
Console.WriteLine(x != y);
Console.WriteLine(x > y);
Console.WriteLine(x < y);
Console.WriteLine(x >= y);
Console.WriteLine(x <= y);
}
}
}
 Assume variable A holds Boolean value true
and variable B holds Boolean value false
 Bitwise operator works on bits and perform
bit by bit operation. The truth tables for &, |,
and ^ are as follows
 Assume variable A holds 60 and variable B
holds 13
unit 1 (1).pptx
unit 1 (1).pptx
unit 1 (1).pptx
unit 1 (1).pptx
unit 1 (1).pptx
 conditional statements
 Looping
 Jumping
use the if statement
 to specify a block of C# code to be executed
if a condition is True.
if statement
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
if (20 > 18)
{
Console.WriteLine("20 is greater than 18");
}
}
}
}
Output
20 is greater than 18
 Use the else statement to specify a block of code to be executed if the
condition is False.
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int time = 20;
if (time < 18)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
}
}
}
}Output:
Good evening
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int time = 22;
if (time < 10)
{
Console.WriteLine("Good morning.");
}
else if (time < 20)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
}
}
}
}
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int time = 20;
string result = (time < 18) ? "Good day." :
"Good evening.";
Console.WriteLine(result);
}
}
}
 For loop
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 10; i = i + 2)
{
Console.WriteLine(i);
}
}
}
}
Output
0
2
4
6
8
10
Nested loop
class Program
{
static void Main(string[] args)
{
// Outer loop
for (int i = 1; i <= 2; ++i)
{
Console.WriteLine("Outer: " + i); // Executes 2 times
// Inner loop
for (int j = 1; j <= 3; j++)
{
Console.WriteLine(" Inner: " + j); // Executes 6 times (2 * 3)
}
}
}
}
}
Nested loop
Output
Outer: 1
Inner: 1
Inner: 2
Inner: 3
Outer: 2
Inner: 1
Inner: 2
Inner: 3
foreach
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
foreach (string i in cars)
{
Console.WriteLine(i);
}
}
}
}
Output
Volvo
BMW
Ford
Mazda
 The while loop- loops through a block of code as long as a
specified condition is True
 Example
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int i = 0;
while (i < 5)
{
Console.WriteLine(i);
i++;
}
}
}
}
output
0
1
2
3
4
 This loop will execute the code block once,
before checking if the condition is true, then
it will repeat the loop as long as the condition
is true.
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
int i = 0;
do
{
Console.WriteLine(i);
i++;
}
while (i < 5);
}
}
}
output
0
1
2
3
4
 switch statement to select one of many code
blocks to be executed.
 how it works?
 The switch expression is evaluated once
 The value of the expression is compared with
the values of each case
 If there is a match, the associated block of
code is executed
class Program
{
static void Main(string[] args)
{
int day = 4;
switch (day)
{
case 1:
Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
case 4:
Console.WriteLine("Thursday");
break;
case 5:
Console.WriteLine("Friday");
break;
case 6:
Console.WriteLine("Saturday");
break;
case 7:
Console.WriteLine("Sunday");
break;
} } }}
Thursday
 break keyword, it breaks out of the switch
block.
 This will stop the execution of more code and
case testing inside the block.
The break statement can also be used to jump out of a loop.
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
if (i == 4)
{
break;
}
Console.WriteLine(i);
}
}
}
}
Output
0
1
2
3
 The continue statement breaks one iteration
(in the loop), if a specified condition occurs,
and continues with the next iteration in the
loop.
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
if (i == 4)
{
continue;
}
Console.WriteLine(i);
}
}
}
}
0
1
2
3
5
6
7
8
9

More Related Content

unit 1 (1).pptx

  • 2.  C# (pronounced "C sharp") is a simple, modern, object- oriented, and type-safe programming language.  C# combines the high productivity of Rapid Application Development (RAD) languages and the raw power of C++  Visual C# .NET is Microsoft's C# development tool  It includes an interactive development environment, visual designers for building Windows and Web applications.
  • 3.  Visual C# .NET is part of a suite of products, called Visual Studio .NET, that also includes Visual Basic .NET, Visual C++ .NET, and the Jscript scripting language.  All of these languages provide access to the Microsoft .NET Framework, which includes a common execution engine and a rich class library
  • 4.  It is a modern, general-purpose programming language  It is object oriented.  It is component oriented.  It is easy to learn.  It is a structured language.  It produces efficient programs.  It can be compiled on a variety of computer platforms.  It is a part of .Net Framework.
  • 5.  Like c++, both single and multiline comments supports  C# builds on the ◦ High performance [c] ◦ Object oriented structure ( c++) ◦ Security ( java) ◦ Rapid development ( visual basic)
  • 6. namespace HelloWorldApplication { class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); } } OUTPUT Hello,world
  • 7.  The source code for a C# program is typically stored in one or more text files with a file extension of .cs, as in hello.cs.  The source code for a C# program is typically stored in one or more text files with a file extension of .cs, as in hello.cs.
  • 9.  using System- directive references a namespace called System that is provided by the Microsoft .NET Framework class library.
  • 10.  A variable is nothing but a name given to a storage area that our programs can manipulate.  Each variable in C# has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.
  • 11. Type Example Integral types sbyte, byte, short, ushort, int, uint, long, ulong, and char Floating point types float and double Decimal types decimal Boolean types true or false values, as assigned Nullable types Nullable data types
  • 12. Syntax for variable <data_type> <variable_list>; Example int i, j, k; char c, ch; float f, salary; double d;
  • 13. Initializing Variables syntax <data_type> <variable_name> = value; Example int d = 3, f = 5; double pi = 3.14159; char x = 'x';
  • 14. using System; namespace VariableDefinition { class Program { static void Main(string[] args) { short a; int b ; double c; a = 10; b = 20; c = a + b; Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c); Console.ReadLine(); } Output: a = 10, b = 20, c = 30
  • 15. Example int num; num = Convert.ToInt32(Console.ReadLine());  The function Convert.ToInt32() converts the data entered by the user to int data type,because Console.ReadLine() accepts the data in string format.  lvalue: An expression that is an lvalue may appear as either the left-hand or  right-hand side of an assignment.  rvalue: An expression that is an rvalue may appear on the right- but not lefthand side of an assignment.  Variables are lvalues and hence they may appear on the left-hand side of an assignment. Numeric literals are rvalues and hence they may not be assigned and can not appear on the left-hand side
  • 16. Single-line Comments  Single-line comments start with two forward slashes (//). Example // This is a comment Console.WriteLine("Hello World!"); C# Multi-line Comments  Multi-line comments start with /* and ends with */.
  • 17. data type specifies the size and type of variable values.  Value types  Reference types  Pointer types
  • 18. Data Type Size Description int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647 long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits bool 1 bit Stores true or false values char 2 bytes Stores a single character/letter, surrounded by single quotes string 2 bytes per character Stores a sequence of characters, surrounded by double q
  • 19.  Value type variables can be assigned a value directly  They are derived from the class System.ValueType.  The value types directly contain data  examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively.  The system allocates memory to store the value
  • 20. using System; namespace MyApplication { class Program { static void Main(string[] args) { int myNum = 100000; Console.WriteLine(myNum); } } }
  • 21. using System; namespace MyApplication { class Program { static void Main(string[] args) { long myNum = 15000000000L; Console.WriteLine(myNum); } } } Output 15000000000
  • 22. using System; namespace MyApplication { class Program { static void Main(string[] args) { float myNum = 5.75F; Console.WriteLine(myNum); } } } Output 5.75
  • 23.  Use float or double  The precision of a floating point value indicates how many digits the value can have after the decimal point. The precision of float is only six or seven decimal digits, while double variables have a precision of about 15 digits. Therefore it is safer to use double for most calculations.
  • 24. using System; namespace MyApplication { class Program { static void Main(string[] args) { double myNum = 19.99D; Console.WriteLine(myNum); } } } Output 19.99
  • 25. A floating point number can also be a scientific number with an "e" to indicate the power of 10: using System; namespace MyApplication { class Program { static void Main(string[] args) { float f1 = 35e3F; double d1 = 12E4D; Console.WriteLine(f1); Console.WriteLine(d1); } } } Output 35000 120000
  • 26.  The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.  they refer to a memory location  Using multiple variables, the reference types can refer to a memory location.  If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.  Example- object,dynamic, and string
  • 27.  The Object Type is the ultimate base class for all data types in C# Common Type System (CTS).  The object types can be assigned values of any other types, value types, reference types, predefined or userdefined types.  However, before assigning values, it needs type conversion  When a value type is converted to object type, it is called boxing  when an object type is converted to a value type, it is called unboxing object obj; obj = 100; // this is boxing Int b=(int)obj//unboxing
  • 28.  We can store any type of value in the dynamic data type variable.  Type checking for these types of variables takes place at run-time.  Syntax  dynamic <variable_name> = value;  example  dynamic d = 20;  Dynamic types are similar to object types except that type checking for object type  variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.
  • 29.  String Type  The String Type allows you to assign any string values to a variable  The string type is an alias for the System.String class. Example String str = "Adithya Institute of Technology";
  • 30.  Pointer type variables store the memory address of another type.  Pointers in C# have the same capabilities as the pointers in C or C++.  Syntax  type* identifier;  example  char* cptr;  int* iptr;
  • 31.  Implicit Casting (automatically) - converting a smaller type to a larger type size char -> int -> long -> float -> double  Explicit Casting (manually) - converting a larger type to a smaller size type double -> float -> long -> int -> char
  • 32. using System; namespace MyApplication { class Program { static void Main(string[] args) { int myInt = 9; double myDouble = myInt; // Automatic casting: int to double Console.WriteLine(myInt); Console.WriteLine(myDouble); } } }
  • 33. using System; namespace MyApplication { class Program { static void Main(string[] args) { double myDouble = 9.78; int myInt = (int) myDouble; // Manual casting: double to int Console.WriteLine(myDouble); Console.WriteLine(myInt); } } }
  • 34.  1. Arithmetic Operators  2. Relational Operators  3. Logical Operators  4. Bitwise Operators  5. Assignment Operators  6. Misc Operators
  • 35. Operator Name Description Example + Addition Adds together two values x + y - Subtraction Subtracts one value from another x - y * Multiplication Multiplies two values x * y / Division Divides one value by another x / y % Modulus Returns the division remainder x % y ++ Increment Increases the value of a variable by 1 x++ -- Decrement Decreases the value of a variable by 1 x--
  • 36. using System; namespace MyApplication { class Program { static void Main(string[] args) { int x = 5; int y = 2; Console.WriteLine(x+y); Console.WriteLine(x-y); Console.WriteLine(x*y); Console.WriteLine(x/y); Console.WriteLine(x % y); Console.WriteLine(x++); Console.WriteLine(x--); } } }
  • 37. Operator Name Example == Equal to x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 39. using System; namespace MyApplication { class Program { static void Main(string[] args) { int x = 5; int y = 3; Console.WriteLine(x == y); Console.WriteLine(x != y); Console.WriteLine(x > y); Console.WriteLine(x < y); Console.WriteLine(x >= y); Console.WriteLine(x <= y); } } }
  • 40.  Assume variable A holds Boolean value true and variable B holds Boolean value false
  • 41.  Bitwise operator works on bits and perform bit by bit operation. The truth tables for &, |, and ^ are as follows
  • 42.  Assume variable A holds 60 and variable B holds 13
  • 48.  conditional statements  Looping  Jumping use the if statement  to specify a block of C# code to be executed if a condition is True.
  • 49. if statement using System; namespace MyApplication { class Program { static void Main(string[] args) { if (20 > 18) { Console.WriteLine("20 is greater than 18"); } } } } Output 20 is greater than 18
  • 50.  Use the else statement to specify a block of code to be executed if the condition is False. using System; namespace MyApplication { class Program { static void Main(string[] args) { int time = 20; if (time < 18) { Console.WriteLine("Good day."); } else { Console.WriteLine("Good evening."); } } } }Output: Good evening
  • 51. using System; namespace MyApplication { class Program { static void Main(string[] args) { int time = 22; if (time < 10) { Console.WriteLine("Good morning."); } else if (time < 20) { Console.WriteLine("Good day."); } else { Console.WriteLine("Good evening."); } } } }
  • 52. using System; namespace MyApplication { class Program { static void Main(string[] args) { int time = 20; string result = (time < 18) ? "Good day." : "Good evening."; Console.WriteLine(result); } } }
  • 53.  For loop using System; namespace MyApplication { class Program { static void Main(string[] args) { for (int i = 0; i <= 10; i = i + 2) { Console.WriteLine(i); } } } }
  • 55. Nested loop class Program { static void Main(string[] args) { // Outer loop for (int i = 1; i <= 2; ++i) { Console.WriteLine("Outer: " + i); // Executes 2 times // Inner loop for (int j = 1; j <= 3; j++) { Console.WriteLine(" Inner: " + j); // Executes 6 times (2 * 3) } } } } }
  • 56. Nested loop Output Outer: 1 Inner: 1 Inner: 2 Inner: 3 Outer: 2 Inner: 1 Inner: 2 Inner: 3
  • 57. foreach namespace MyApplication { class Program { static void Main(string[] args) { string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; foreach (string i in cars) { Console.WriteLine(i); } } } }
  • 59.  The while loop- loops through a block of code as long as a specified condition is True  Example namespace MyApplication { class Program { static void Main(string[] args) { int i = 0; while (i < 5) { Console.WriteLine(i); i++; } } } }
  • 61.  This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.
  • 62. namespace MyApplication { class Program { static void Main(string[] args) { int i = 0; do { Console.WriteLine(i); i++; } while (i < 5); } } }
  • 64.  switch statement to select one of many code blocks to be executed.  how it works?  The switch expression is evaluated once  The value of the expression is compared with the values of each case  If there is a match, the associated block of code is executed
  • 65. class Program { static void Main(string[] args) { int day = 4; switch (day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; case 5: Console.WriteLine("Friday"); break; case 6: Console.WriteLine("Saturday"); break; case 7: Console.WriteLine("Sunday"); break; } } }}
  • 67.  break keyword, it breaks out of the switch block.  This will stop the execution of more code and case testing inside the block.
  • 68. The break statement can also be used to jump out of a loop. namespace MyApplication { class Program { static void Main(string[] args) { for (int i = 0; i < 10; i++) { if (i == 4) { break; } Console.WriteLine(i); } } } }
  • 70.  The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
  • 71. namespace MyApplication { class Program { static void Main(string[] args) { for (int i = 0; i < 10; i++) { if (i == 4) { continue; } Console.WriteLine(i); } } } }