Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C# Operators


Sure! In C#, operators are symbols that perform operations on operands, such as variables, constants, and expressions. Here are some common operators in C# explained with examples:

  1. Arithmetic Operators: These operators are used to perform arithmetic operations like addition, subtraction, multiplication, division, and modulus.
  2. Example

    int a = 10;
    int b = 5;
    int sum = a + b; // Addition
    int difference = a - b; // Subtraction
    int product = a * b; // Multiplication
    int quotient = a / b; // Division
    int remainder = a % b; // Modulus (remainder after division)

  3. Comparison Operators: These operators are used to compare values. They return a boolean value (true or false) based on the comparison.
  4. Example

    int x = 10;
    int y = 5;
    bool isEqual = (x == y); // Equal to
    bool isNotEqual = (x != y); // Not equal to
    bool isGreater = (x > y); // Greater than
    bool isLess = (x < y); // Less than
    bool isGreaterOrEqual = (x >= y); // Greater than or equal to
    bool isLessOrEqual = (x <= y); // Less than or equal to

  5. Logical Operators: These operators are used to perform logical operations on boolean expressions.
  6. Example

    bool p = true;
    bool q = false;
    bool resultAnd = (p && q); // Logical AND
    bool resultOr = (p || q); // Logical OR
    bool resultNot = !p; // Logical NOT

  7. Assignment Operators: These operators are used to assign values to variables.
  8. Example

    int num = 10;
    num += 5; // Equivalent to: num = num + 5;
    num -= 2; // Equivalent to: num = num - 2;
    num *= 3; // Equivalent to: num = num * 3;
    num /= 2; // Equivalent to: num = num / 2;
    num %= 4; // Equivalent to: num = num % 4;

  9. Increment and Decrement Operators: These operators are used to increase or decrease the value of a variable by 1.
  10. Example

    int count = 0;
    count++; // Increment by 1
    count--; // Decrement by 1

These are some of the basic operators in C#. Understanding and mastering these operators will be essential for writing C# code effectively.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java