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

C# Language Fundamentals

The document provides an overview of C# language fundamentals, detailing data types, variable declarations, and constants. It covers control structures such as loops and conditional statements, as well as arrays and exception handling mechanisms. Additionally, it introduces classes and objects, emphasizing the importance of access modifiers and methods in C# programming.

Uploaded by

maheen.ehsaan.19
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C# Language Fundamentals

The document provides an overview of C# language fundamentals, detailing data types, variable declarations, and constants. It covers control structures such as loops and conditional statements, as well as arrays and exception handling mechanisms. Additionally, it introduces classes and objects, emphasizing the importance of access modifiers and methods in C# programming.

Uploaded by

maheen.ehsaan.19
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

C# Language

Fundamentals
Hina Farooq
Basic Data
Types and their
mapping to CTS

There are two kinds of data types


in C#.
• Value Types (implicit data types,
structs and enumeration)
• Reference Types (objects,
delegates)
Variables, Constant
Variables

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:

variable names following Camel notation could be:


• salary
• totalSalary
• myMathsMarks
• isPaid
Some typical names of method following Pascal Notation are:
• GetTotal()
• Start()
• WriteLine()
• LastIndexOf()
Operators in C#
Arithmetic Operators,
Assignment
Operators,
Relational Operators,
Logical and Bitwise
Operators
If-else
Condition
If you need to perform a series of specific checks,
The switch...case is present in C# just for this

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

Write a C# Sharp program to find out whether a given year is a


Write leap year or not
Write a C# Sharp program to calculate profit and loss on a
Write transaction.
Write a C# Sharp program to calculate the factorial of a given
Write number.
Write a program in C# Sharp to display a right angle triangle with
Write an asterisk.
Write a C# Sharp program to sort array elements in descending
Write order.
Data and
Methods
Class and Object
• A class is simply an abstract model used to define a new data types. A class may
contain any combination of encapsulated data (fields or member variables), operations
that can be performed on data (methods) and accessors to data (properties).
• For example, there is a class String in the System namespace of .Net Framework Class
Library(FCL).
Objects
As mentioned above, a class is an abstract model. An object is the concrete realization or
instance built on the model specified by the class. An object is created in the memory
using the keyword ’new’ and is referenced by an identifier called a "reference".
Access Modifiers or Accessibility Levels
Exception
Handling
Exception handling is a mechanism to
handle run-time errors in .NET that
would otherwise cause your software to
terminate prematurely.
• The code that may throw an exception
which we want to handle is put in the
try block. This is called an attempt to
catch an exception.
• The code to handle the thrown
exception is placed in the catch block
just after the try block. This is called
catching the exception
• Multiple catch blocks can be defined
for a single try block

You might also like