C programming presentation
C programming presentation
Rayan M. Mustafa
Definition of C#
● Example:
● int[] numbers = {1, 2, 3, 4, 5};
● Example:
● int age = 18;
● if (age >= 18) {
● Console.WriteLine("You are an adult.");
● } else {
● Console.WriteLine("You are a minor.");
● }
Example: Variable Declaration and
Initialization
● In C#, you can declare and initialize variables in a single statement.
● Example:
● int number = 10;
● string name = "Alice";
● bool isActive = true;
● Example:
● int a = 10;
● int b = 5;
● int sum = a + b; // sum = 15
● int product = a * b; // product = 50
● int quotient = a / b; // quotient = 2
● int remainder = a % b; // remainder = 0
Example: For Loop
● The 'for' loop is used for iterating over a sequence.
● Example:
● for (int i = 0; i < 5; i++) {
● Console.WriteLine("Value of i: " + i);
● }
● Output:
● Value of i: 0
● Value of i: 1
● Value of i: 2
● Value of i: 3
● Value of i: 4
Example: Methods in C#
● Example:
● public int AddNumbers(int a, int b) {
● return a + b;
●}
● Usage:
● int result = AddNumbers(3, 4); // result = 7
Any Question?
Thank you