- 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:

推薦閱讀
- 大話PLC(輕松動漫版)
- Unreal Engine Physics Essentials
- SQL語言從入門到精通
- D3.js 4.x Data Visualization(Third Edition)
- Unity 2D Game Development Cookbook
- Java編程的邏輯
- 深入理解C指針
- Raspberry Pi Robotic Projects(Third Edition)
- SQL Server 2008 R2數據庫技術及應用(第3版)
- 網絡數據采集技術:Java網絡爬蟲實戰
- 硬件產品設計與開發:從原型到交付
- 進入IT企業必讀的324個Java面試題
- Mudbox 2013 Cookbook
- INSTANT Apache Hive Essentials How-to
- Puppet 5 Beginner's Guide(Third Edition)