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

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:

主站蜘蛛池模板: 洛阳市| 来安县| 苏州市| 青海省| 乌兰浩特市| 玛多县| 资阳市| 长顺县| 东莞市| 大渡口区| 桂阳县| 凌源市| 汽车| 葫芦岛市| 桐城市| 云龙县| 台东市| 丰县| 萝北县| 吉水县| 勃利县| 哈尔滨市| 海宁市| 梁山县| 河北省| 墨脱县| 石渠县| 绥德县| 六安市| 阳东县| 宁河县| 曲阜市| 德钦县| 高雄市| 安远县| 安西县| 镇远县| 河北区| 鄢陵县| 三台县| 乐业县|