Monday 8 May 2023

C# Operator Overview

 In C#, an operator is a symbol or keyword that represents a specific action to be performed on one or more operands. C# provides a wide range of operators that are used for arithmetic, logical, relational, and bitwise operations.


Here are some of the most commonly used operators in C#:


1. Arithmetic Operators: These operators are used to perform basic arithmetic operations on numeric values. The arithmetic operators in C# include + (addition), - (subtraction), * (multiplication), / (division), % (modulus), ++ (increment), and -- (decrement).


2. Logical Operators: These operators are used to perform logical operations on Boolean values. The logical operators in C# include && (logical AND), || (logical OR), and ! (logical NOT).


3. Relational Operators: These operators are used to compare two values and return a Boolean value indicating whether the comparison is true or false. The relational operators in C# include == (equality), != (inequality), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to).


4. Bitwise Operators: These operators are used to perform bitwise operations on integer values. The bitwise operators in C# include & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), and >> (right shift).


5. Assignment Operators: These operators are used to assign a value to a variable. The assignment operators in C# include = (simple assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), /= (division assignment), and %= (modulus assignment).


6. Conditional Operators: These operators are used to evaluate a Boolean expression and return one of two values based on the result. The conditional operators in C# include ?: (ternary operator).


In addition to these basic operators, C# also provides several other operators for specific purposes, such as the is operator for type checking, the as operator for type casting, and the sizeof operator for determining the size of a value type.

No comments:

Post a Comment

Draw Circle in C#

 Here's an example program in C# that uses the `System.Drawing` namespace to draw a circle on a Windows Form: // Mohit Kumar Tyagi using...