官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 罗源县| 建昌县| 大埔县| 桐梓县| 区。| 海丰县| 蓬莱市| 桂阳县| 阳西县| 济南市| 东港市| 白山市| 准格尔旗| 睢宁县| 丰原市| 巫山县| 义乌市| 阳谷县| 济源市| 集安市| 江津市| 镇沅| 宁陵县| 称多县| 涡阳县| 宣汉县| 哈密市| 长阳| 闻喜县| 广饶县| 五家渠市| 望江县| 沁阳市| 合山市| 宝兴县| 怀集县| 德昌县| 湾仔区| 五台县| 西和县| 离岛区|