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

推薦閱讀
- Visual FoxPro程序設(shè)計(jì)教程(第3版)
- Unity 2020 Mobile Game Development
- Practical DevOps
- Internet of Things with Intel Galileo
- Oracle BAM 11gR1 Handbook
- Amazon S3 Cookbook
- EPLAN實(shí)戰(zhàn)設(shè)計(jì)
- Highcharts Cookbook
- C# 8.0核心技術(shù)指南(原書第8版)
- Julia高性能科學(xué)計(jì)算(第2版)
- 低代碼平臺(tái)開(kāi)發(fā)實(shí)踐:基于React
- Building Android UIs with Custom Views
- ASP.NET程序開(kāi)發(fā)范例寶典
- FPGA嵌入式項(xiàng)目開(kāi)發(fā)實(shí)戰(zhàn)
- 青少年學(xué)Python(第2冊(cè))