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

推薦閱讀
- Clojure Programming Cookbook
- Puppet 4 Essentials(Second Edition)
- 基于粒計算模型的圖像處理
- Node.js Design Patterns
- Visual FoxPro程序設計教程(第3版)
- 軟件測試項目實戰之性能測試篇
- Java程序員面試算法寶典
- Web程序設計(第二版)
- C#程序設計基礎:教程、實驗、習題
- 零基礎入門學習Python
- C#程序設計
- ElasticSearch Cookbook(Second Edition)
- Julia 1.0 Programming Complete Reference Guide
- Visual Basic程序設計習題與上機實踐
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通