- Learn C# in 7 days
- Gaurav Aroraa
- 178字
- 2021-07-08 09:51:26
Operators
In C#, operators are nothing but mathematical or logical operators that tell the compiler to perform a specific operation. For instance, a multiplication (*) operator tells the compiler to multiply; on the other hand, the logical and (&&) operator checks both the operands. We can divide C# operators into broader types, as shown in the following table:

Take a look at the following code snippet, which implements all operators discussed previously:
private void ArithmeticOperators() { WriteLine("\nArithmetic operators\n"); WriteLine($"Operator '+' (add): {nameof(Num1)} + {nameof(Num2)} = {Num1 + Num2}"); WriteLine($"Operator '-' (substract): {nameof(Num1)} - {nameof(Num2)} = {Num1 - Num2}"); WriteLine($"Operator '*' (multiplication): {nameof(Num1)} * {nameof(Num2)} = {Num1 * Num2}"); WriteLine($"Operator '/' (division): {nameof(Num1)} / {nameof(Num2)} = {Num1 / Num2}"); WriteLine($"Operator '%' (modulus): {nameof(Num1)} % {nameof(Num2)} = {Num1 % Num2}"); WriteLine($"Operator '++' (incremental): pre-increment: ++{nameof(Num1)} = {++Num1}"); WriteLine($"Operator '++' (incremental): post-increment: {nameof(Num1)}++ = {Num1++}"); WriteLine($"Operator '--' (decremental): pre-decrement: --{nameof(Num2)} = {--Num2}"); WriteLine($"Operator '--' (decremental): post-decrement: {nameof(Num2)}-- = {Num2--}"); ReadLine(); } //Code omitted
The complete code is available on the GitHub repository, and it produces the following results:

推薦閱讀
- Kali Linux Web Penetration Testing Cookbook
- Python for Secret Agents:Volume II
- Mastering Python Scripting for System Administrators
- Elastic Stack應(yīng)用寶典
- 重學(xué)Java設(shè)計模式
- Mastering JavaScript High Performance
- Getting Started with LLVM Core Libraries
- Kubernetes源碼剖析
- Go語言開發(fā)實戰(zhàn)(慕課版)
- Python數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南(全彩)
- OpenCV Android Programming By Example
- Penetration Testing with the Bash shell
- 計算機應(yīng)用基礎(chǔ)(第二版)
- HTML5程序設(shè)計基礎(chǔ)教程
- R語言數(shù)據(jù)分析從入門到實戰(zhàn)