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

Statement Operators in Chsarp

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Statement Operators in Chsarp

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

STATEMENTS,

EXPRESSIONS AND
OPERATORS IN C#
STATEMENTS

• A C# program is a set of tasks that perform to achieve the overall


functionality of the program.
• To perform the tasks, programmers provide instructions. These
instructions are called statements.
• A C# statement can contain expressions that evaluates to a value.
STATEMENTS

• Statements are referred to as logical grouping of variables,


operators, and C# keywords that perform a specific task.
• For example, the line which initializes a variable by assigning it a
value is a statement.
• In C#, a statement ends with a semicolon.
• A C# program contains multiple statements grouped in blocks. A
block is a code segment enclosed in curly braces.
STATEMENTS
• For example, the set of statements included in the Main() method
of a C# code is a block.
STATEMENTS
• Statements are used to specify the input, the process, and the output
tasks of a program. Statements can consist of:
• Data types
• Variables
• Operators
• Constants
• Literals
• Keywords
• Escape sequence characters
STATEMENTS

• Statements help you build a logical flow in the program. With the
help of statements, you can:
• Initialize variables and objects
• Take the input
• Call a method of a class
• Display the output
TYPES OF STATEMENTS
• Similar to statements in C and C++, the C# statements are
• classified into seven categories:
• Selection Statements
• Iteration Statements
• Jump Statements
• Exception Handling Statements
EXPRESSIONS

• Expressions are used to manipulate data. Like in mathematics,


expressions in programming languages, including C#, are
constructed from the operands and operators.
• Example: 2 + 2
• An expression statement in C# ends with a semicolon (;).
• The following code demonstrates an example for expressions:
• simpleInterest = principal * time * rate / 100;
OPERATORS

• Expressions in C# comprise one or more operators that performs some


operations on variables.
• An operation is an action performed on single or multiple values stored
in variables in order to modify them or to generate a new value with
the help of minimum one symbol and a value.
• The symbol is called an operator and it determines the type of action to
be performed on the value.
OPERATORS

• An operand might be a complex expression. For example, (X * Y) +


(X – Y) is a complex expression, where the + operator is used to
join two operands.
• The value on which the operation is to be performed is called an
operand.
OPERATORS
• Operators are used to simplify expressions.
• In C#, there is a predefined set of operators used to perform various types of
operations.
• These are classified into seven categories based on the action they perform
on values:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Conditional Operators
• Increment and Decrement Operators
• Assignment Operators
CLASSIFICATION OF
OPERATORS

• Operators are classify into 3 categories:


• 1. UNARY OPERATORS
• 2. BINARY OPERATORS
• 3. TERNARY OPERATORS
ARITHMETIC OPERATORS

• Arithmetic operators are binary operators because they work with


two operands, with the operator being placed in between the
operands.
• These operators allow you to perform computations on numeric or
string data.
ARITHMETIC OPERATORS

•+
•-
•/
•*
•%
ARITHMETIC OPERATORS
RELATIONAL OR COMPARISON
OPERATORS
• Relational operators make a comparison between two operands
and return a boolean value, true, or false.
• ==
• !=
• >
• <
• >=
• <=
LOGICAL OR CONDITIONAL
OPERATORS

• logical operators perform boolean logical operations on both the


operands. They return a boolean value based on the logical
operator used.

There are two types of conditional operators.
• CONDITIONAL AND (&&)
• CONDITIONAL OR (||).
LOGICAL OR CONDITIONAL
OPERATORS

• logical operators perform boolean logical operations on both the


operands. They return a boolean value based on the logical operator
used.

There are two types of conditional operators.
• CONDITIONAL AND (&&)
• CONDITIONAL OR (||).
LOGICAL OR CONDITIONAL
OPERATORS

• logical operators perform boolean logical operations on both the


operands. They return a boolean value based on the logical operator
used.

There are two types of conditional operators.
• CONDITIONAL AND (&&)
• CONDITIONAL OR (||).
ASSIGNMENT OPERATORS

• Assignment operators are used to assign the value of the right side
operand to the operand on the left side using the equal to operator (=).
• The assignment operators are divided into two categories in C#. These
are as follows:
• Simple assignment operators: The simple assignment operator is =,
which is used to assign a value or result of an expression to a variable.
• Compound assignment operators: The compound assignment
operators are formed by combining the simple assignment operator with
the arithmetic operators.
ASSIGNMENT OPERATORS

• Compound assignment operators:


• +=
• -=
• *=
• /=
• %=
INCREMENT AND DECREMENT
OPERATORS
• Two of the most common calculations performed in programming
are increasing and decreasing the value of the variable by 1.
• In C#, the increment operator (++) is used to increase the value by
1 while the decrement operator (--) is used to decrease the value
by 1.
• If the operator is placed before the operand, the expression is
called pre-increment or pre-decrement.
• If the operator is placed after the operand, the expression is called
post-increment or post-decrement.
TERNARY OR CONDITIONAL
OPERATORS
• C# includes a special type of decision making operator ? : called
the ternary operator.
• Syntax:
• Boolean Expression ? First Statement : Second Statement
PRECEDENCE OF
OPERATORS
• Operators in C# have certain associated priority levels.
• The C# compiler executes operators in the sequence defined by
the priority level of the operators.
• EXAMPLE:
• 8/2-3+2*2

You might also like