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 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 { }.

For example, the set of statements included in the Main() method of a C# code is a block.

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

Similar to statements in C and C++, the C# statements are classified into several categories:

  • Selection Statements
  • Iteration Statements
  • Jump Statements
  • Exception Handling Statements
  • ETC

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.
  • 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 are used to simplify expressions.
  • In C#, there is a predefined set of operators used to perform various types of operations.

Classification Of Operators

Operators are classify into 3 categories:

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

These are seven types of operators based on the action they perform on values:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Conditional Operators
  • Increment and Decrement Operators
  • Assignment Operators

Click Below Link to Download Notes Of This Blog

https://www.mediafire.com/file/uws983l62oz06wq/STATEMENT+OPERATORS+IN+CHSARP.pptx/file

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *