0% found this document useful (0 votes)
34 views

C programming presentation

C1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

C programming presentation

C1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Introduction to C#

An Overview of the C# Programming


Language

Rayan M. Mustafa
Definition of C#

● C# is a modern, object-oriented programming language developed by


Microsoft. It is widely used for building Windows applications, games,
and web applications through the .NET framework. C# combines the
power of C++ and the ease of Java, making it a popular choice for
developers.
Basic C# Syntax
● Here are some basic syntax rules in C#:
● - Variable declaration: int number = 5;
● - Data types: int, float, string, bool
● - Operators: +, -, *, /, %

● C# syntax is similar to other C-based languages like Java and C++.


Arrays in C#
● An array in C# is a collection of elements of the same type stored in contiguous
memory.

● Example:
● int[] numbers = {1, 2, 3, 4, 5};

● Access elements by index, e.g., numbers[0] will return 1.


If Conditions in C#
● If conditions allow you to execute code based on specific conditions.

● 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;

● Each variable is assigned a value based on its type.


Example: Basic Math Operations
● C# supports various arithmetic operations.

● 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#

● Methods in C# allow you to encapsulate code into reusable functions.

● Example:
● public int AddNumbers(int a, int b) {
● return a + b;
●}

● Usage:
● int result = AddNumbers(3, 4); // result = 7
Any Question?
Thank you

You might also like