Introduction to C# x
C# is a general purpose, object-oriented programming
language developed by Microsoft in 2002.
C# is designed for Common Language Infrastructure
(CLI), which consists of executable code and runtime
environment that allows the use of various high-level
languages on different computer platforms and
architectures.
Sarbendra sigdel
Literals in C# x
Unit Literals String Literals
Int Literals char Literals
Sbyte Literals Byte Literals
Decimal Literals Short Literals
Double Literals Ushort Literals
Float Literals Bool Literals
Long Literals
ULong Literals
s.sigdel
Operators in C# x
Arithmetic Operators
+ - * / %
Relational Operators
== != < > <= >=
Logical Operators
&& || !
s.sigdel
Operators in C# x
Assignment Operators
= += -= *= /= %=
Bitwise Operators
& | ^ ~ << >>
Unary Operators
+ - ++ -- !
s.sigdel
Operators in C# x
Ternary Operator
?:
Null-Coalescing Operators
?? ??=
Type Operators
is, as, typeof, sizeof
s.sigdel
Operators in C# x
Index and Range Operators
[] ^
s.sigdel
Conditional statements in C# x
if, else if, else
if (score >= 90)
Console.WriteLine("distinction!");
else if (score >= 50)
Console.WriteLine("Passed!");
else
Console.WriteLine("Failed!");
s.sigdel
Conditional statements in C# x
Switch
switch (expression) {
case value1:
// Code block
break;
case value2:
// Code block
break;
default:
// Default code block
break;
}
s.sigdel
Loops in C# x
For Loop :
Best for known iterations
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i);
}
Output:
12345
s.sigdel
Loops in C# x
While Loop :
Runs while a condition is true
int i = 1;
while (i <= 5)
{
Console.WriteLine(i);
i++;
}
Output:
12345
s.sigdel
Loops in C# x
Do While Loop :
Runs at least once, then checks the condition
int i = 1;
do
{
Console.WriteLine(i);
i++;
} while (i <= 5);
Output:
12345
s.sigdel
Loops in C# x
Foreach Loop :
The foreach loop is used to iterate through each element in a
collection (like an array or list)
string[ ] fruits = { "Apple", "Banana", "Cherry",
"Mango" };
foreach (string fruit in fruits)
{
Console.WriteLine(fruit);
}
Output:
Apple Banana Cherry Mango
s.sigdel
Why C# x
Powerful and Versatile Secure and Reliable
Game Development
Cross-Platform
Beginner-Friendly
Strong Community & Resources
High Performance
s.sigdel