C# Language Fundamentals
C# Language Fundamentals
Fundamentals
Hina Farooq
Basic Data
Types and their
mapping to CTS
Variables:
During the execution of a program, data is temporarily stored in
memory. A variable is the name given to a
memory location holding a particular type of data.
In C#, variables are declared as:
<data type> <variable>;
e.g.,
int i;
Constant Variables:
Constants are variables whose values, once defined, can not be
changed by the program. Constant variables are
declared using the const keyword, like:
const double PI = 3.142;
const int MARKS;
Working with
string and
number
User Input
Camel Case/pascal case:
switch...case
statement
Loops In C#
While Loops:
The while loop is similar to the do...while
loop, except that it checks the condition
before entering the first iteration
(execution of code inside the body of the
loop).
while (condition)
{
// Code to execute
}
The statements under do will execute the first time and then the condition is
checked. The loop will continue while the condition remains true.
do...while do
Loop
{
// Code to execute
} while (condition);
for (initialization; condition; iteration)
for Loop
{
// Code to execute
}
Array Declaration
• An Array is a collection of values of a similar data
type. Technically, C# arrays are a reference type.
Arrays in C#
• Each array in C# is an object and is inherited from
the System.Array class.
<data type> [] <identifier> = new <data
type>[<size of array>];
int [] integers = new int[10];
Practice
question
Practice Question
Write Write a C# Sharp program to swap two numbers