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

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

主站蜘蛛池模板: 绵竹市| 玉门市| 清徐县| 泰和县| 宁国市| 二连浩特市| 绍兴市| 微博| 神农架林区| 遵义市| 无棣县| 德令哈市| 望奎县| 马边| 博爱县| 阿拉善右旗| 台山市| 昆山市| 萍乡市| 温宿县| 成武县| 新兴县| 西乌| 句容市| 罗田县| 巴中市| 夏河县| 和林格尔县| 进贤县| 仁怀市| 平塘县| 龙门县| 邵东县| 永丰县| 穆棱市| 静乐县| 镶黄旗| 石林| 同心县| 阜宁县| 故城县|