0% found this document useful (0 votes)
50 views23 pages

Module 3 - Variables, Data Types and Operators

This document provides an overview of variables, data types, and operators in C# programming. It defines variables as storage locations for data and lists the fundamental data types in C# like int, float, double, char, bool, and string. It also discusses operators that perform actions on operands, including arithmetic, relational, logical, and assignment operators. The document explains operator precedence and provides examples of how expressions are evaluated based on these precedence rules. The overall goals are to discuss C# data types, learn different types of operators, and demonstrate correct use of operators and their hierarchy in C# programs.

Uploaded by

PizzaTobacco123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
50 views23 pages

Module 3 - Variables, Data Types and Operators

This document provides an overview of variables, data types, and operators in C# programming. It defines variables as storage locations for data and lists the fundamental data types in C# like int, float, double, char, bool, and string. It also discusses operators that perform actions on operands, including arithmetic, relational, logical, and assignment operators. The document explains operator precedence and provides examples of how expressions are evaluated based on these precedence rules. The overall goals are to discuss C# data types, learn different types of operators, and demonstrate correct use of operators and their hierarchy in C# programs.

Uploaded by

PizzaTobacco123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 23

Module 3

Variables, Data
Types and Operators
How Programmers Propose?

The Greatest Geeky Marriage Proposals of All Time


http://www.willyoumarrymekc.com/geeky-proposals/

“Progress is possible only if we
train ourselves to think about
programs without thinking of them
as pieces of executable code. ”
― Edsger W. Dijkstra
COURSE INTENDED
LEARNING OUTCOMES
CILO 2:
Demonstrate different uses of operators by using them in writing a
C# program.
LESSON
OBJECTIVES
Discuss the different C# data types.
Learn different types of operators
Demonstrate the correct use of C# operators and their hierarchy

Create C# programs using variables, operators, and data types


Variables Defined
• Variables” are simply storage locations for data.
• You can place data into them and retrieve their contents as part
of a C# expression.
General Format:

data_type variable_name;

wherein:
• data_type is any valid data type in C#
• variable_name is any valid identifier in C#
Rules in naming an Identifier

1. Identifier is composed of alphanumeric characters (A-Z, a-z, 0-9,


and _).
2. An identifier should not start with a number.
3. An identifier should not have any white space.
4. An identifier should not be a C# reserved word or keyword.
5. Identifiers are case sensitive in C#.
General Format:

const data_type const_name = "value";

wherein:
• const - is a C# keyword. It tells C# that you are using a constant.
• const_name - is any valid identifier given to the constant.
• value - is the initial value assigned to the constant
C# Data Types
• C# is a “Strongly Typed” language.
• All operations on variables are performed with consideration of
what the variable’s “Type” is.
• There are rules that define what operations are legal to maintain
the integrity of the data you put in a variable.
Fundamental Data Types
C# Data Types
Type Description Range
int 32-bit signed integer -2,147,483,648 to 2,147,483,647

float 32-bit Single-precision floating point type -3.402823e38 to 3.402823e38

double 64-bit double-precision floating point type -1.79769313486232e308 to


1.79769313486232e308

char 16-bit single Unicode character Any valid character, e.g. a,*, \x0058 (hex),
or\u0058 (Unicode)

bool 8-bit logical true/false value True or False

string A sequence of Unicode characters


Example:
Example:
C# Operators
• Operators in C# are special symbols that perform some action on
operands.
• Most of these operators are similar to the operators that you use
in Mathematics.
Operators Commonly Used in Flowcharting
Arithmetic Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
Operators Commonly Used in Flowcharting
Relational/Comparison Operators Meaning

= Assignment Operator

> Greater Than

< Less Than

<> Not Equal

>= Greater than or equal to

<= Lesser than or equal to


Operators Commonly Used in Flowcharting
Logical Operators Meaning

&& AND

|| OR

! NOT
Operator Precedence
• Operator precedence is a set of rules which defines how an
expression is evaluated.
• Each C# operator has an assigned priority and based on these
priorities, the expression is evaluated.
• The higher the precedence of operator is, the higher it appears in
the table
Table of Precedence
Example No.1
Thanks!
Any questions?
References:
• https://www.tutorialsteacher.com/csharp/csharp-operators
• https://www.tutlane.com/tutorial/csharp/csharp-operators-
precedence-with-examples

You might also like