Forum

Learn .Net Operator…
 
Notifications
Clear all

Learn .Net Operators

1 Posts
1 Users
0 Reactions
9 Views
 josh
(@josh)
Member Admin
Joined: 2 months ago
Posts: 510
Topic starter  

In .NET (especially C#), operators are symbols or keywords that perform operations on variables and values—things like arithmetic, comparison, and logic. Let’s break it down:


➕ Arithmetic Operators

  • + : addition
  • - : subtraction
  • * : multiplication
  • / : division
  • % : modulus (remainder)
int result = 7 + 3;  // result is 10

⚖️ Comparison Operators

Used in conditions to compare values:

  • == : equal to
  • != : not equal to
  • > : greater than
  • < : less than
  • >= : greater than or equal to
  • <= : less than or equal to
bool isEqual = (5 == 5);  // true

🔄 Logical Operators

Great for combining Boolean expressions:

  • && : logical AND
  • || : logical OR
  • ! : logical NOT
if (isSunny && isWarm) {
    Console.WriteLine("Perfect weather!");
}

🧠 Bitwise Operators

Operate at the binary level:

  • & : AND
  • | : OR
  • ^ : XOR
  • ~ : NOT
  • << : left shift
  • >> : right shift

🧩 Assignment Operators

Set and modify variable values:

  • = : assign
  • +=, -=, *=, /=, %= : shorthand for arithmetic + assignment
x += 5;  // same as x = x + 5

🧪 Other Notables

  • ?? : null-coalescing operator
    string name = input ?? "Guest";
    
  • ?. : null-conditional operator
    user?.SendEmail();  // only calls if user is not null
    

Operators in .NET help make your logic expressive, concise, and powerful. 


   
Quote
Share: