csharp_expressions_contents.md - brainchildservices/curriculum GitHub Wiki

REF link-

C# Operator

Operators are used to perform operations on variables and values.

https://dotnetfiddle.net/ksXJJo

Basic Arithmetic Operators

https://dotnetfiddle.net/UQEmab

Increment and Decrement operator

https://dotnetfiddle.net/czEXLi

Difference between Increment and Decrement Operator https://dotnetfiddle.net/pzQRjz

Assignment Operators https://dotnetfiddle.net/Nhops1

**Comparison Operators ** https://dotnetfiddle.net/kISXsB

Logical Operators https://dotnetfiddle.net/ANhzwJ

What is a C# expressions? An expression in C# is a combination of operands (variables, literals, method calls) and operators that can be evaluated to a single value. c=a+b; a,b,c are the operands.

  • _ operator

What are Operators? Operators are symbols that are used to perform operations on operands. Operands may be variables and/or constants. For example, in 2+3, + is an operator that is used to carry out addition operation, while 2 and 3 are operands.

What are Unary operators? the unary operators operates on a single operand. C# unary operators Operator Operator Name Description

  •       Unary Plus	        Leaves the sign of operand as it is
    
  •      Unary Minus	        Inverts the sign of operand
    

++ Increment Increment value by 1 -- Decrement Decrement value by 1 ! Logical Negation (Not) Inverts the value of a boolean

Operator Operator Name Description
+ Unary Plus Leaves the sign of operand as it is
- Unary Minus Inverts the sign of operand
++ Increment Increment value by 1
-- Decrement Decrement value by 1
! Logical Negation (Not) Inverts the value of a boolean

What are Arithmetic operators? Arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, Modulo. Addition : 6 + 3 evaluates to 9 subtraction : 10 - 6 evaluates to 4 multiplication : 4 * 2 evaluates to 8 division : 10 / 5 evaluates to 2 Modulo (Remainder) : 16 % 3 evaluates to 1

What are Logical operators? Logical operators are used to perform logical operation such as and, or. Logical operators operates on boolean expressions (true and false) and returns boolean values. Logical operators are used in decision making and loops.
C# Logical operators

+────────────+────────────+──────────+───────────+
| Operand 1 | Operand 2 | OR (||) | AND (&&) |
+────────────+────────────+──────────+───────────+
| True | True | True | True |
| True | False | True | False |
| False | True | True | False |
| False | False | False | False |
+────────────+────────────+──────────+───────────+

| Operand 1 | Operand 2 | OR (||) | AND (&&) |
|:---------:|:---------:|:-------:|:--------:|
| True | True | True | True |
| True | False | True | False |
| False | True | True | False |
| False | False | False | False |

What are Conditional logical operators?

What is the difference between Post and Pre increment operator?

What is Boolean expression? A Boolean expression is a C# expression that returns a Boolean value: True or False.

int x = 10;
int y = 9;
Console.WriteLine(x > y);

C# - Conditional Operator / Ternary Operator ?: https://www.youtube.com/watch?v=BAf6rB36v8I C# includes a decision-making operator ?: which is called the conditional operator or ternary operator. It is the short form of the if else conditions.

Syntax:
datatype variable= comparison_expression ? true_condtion : false_condtion;
https://dotnetfiddle.net/UkaQIj

Assignment:

  • 1 Declare two double variables and assign values to them. Perform Basic Arithmetic Operations on the two numbers.
  • 2 Declare an integer variable and assign value to it. Perform pre increment on the number. Print the result. Perform post increment on the same variable and print the result.
  • 3 Declare an integer and assign value to it. Declare second integer and assign value to it using Pre decrement of first integer. Print the value of the second variable
  • 4 Declare an integer and assign value to it. Declare another integer of assign value to it using Post decrement of first integer. Print the value of the second variable
  • 5 Declare two integers x and y and assign values to them. Print true/false based on if x and y is between 20 and 100 using AND operator
  • 6 Declare two integers x and y and assign values to them. Print true/false based on if x or y is a positive integer using OR operator
  • 7 Declare an integer variable. Using Assignment Operators,
    Add 5 to the variable and store it to the same variable. Print ne w value of the variable.
    Subtract 15 from the variable and store it to the same variable. Print new value of the variable.
    Multiply variable by 5 and store it to the same variable. Print ne w value of the variable.
    Divide variable by 5 and store it to the same variable. Print new value of the variable.
    Find the remainder when the variable is divided by 7 and store it to the same variable. Print new value of the variable.
  • 8 Using ternary operator assign grade to a student. Declare an integer mark and assign value to it. If mark is more than 90, assign grade A otherwise assign grade B. Print the grade received