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

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

主站蜘蛛池模板: 星子县| 巫溪县| 全州县| 固始县| 温宿县| 张北县| 浮梁县| 武鸣县| 巧家县| 榆林市| 扎囊县| 吉隆县| 饶阳县| 饶阳县| 柯坪县| 英山县| 高唐县| 南昌县| 长寿区| 瑞金市| 青岛市| 乌拉特前旗| 石渠县| 扶绥县| 尤溪县| 泾阳县| 驻马店市| 开原市| 龙胜| 八宿县| 蕉岭县| 疏勒县| 徐闻县| 西乡县| 南陵县| 渭南市| 盖州市| 乐昌市| 聂拉木县| 磐石市| 扬中市|