什么是C#中的算术运算符?
运算符是一个符号,告诉编译器执行特定的数学或逻辑操作。
让我们看一个在C#中使用算术运算符的示例。
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 99;
int b = 33;
int c;
c = a + b;
Console.WriteLine("Value of c is {0}", c);
c = a - b;
Console.WriteLine("Value of c is {0}", c);
c = a * b;
Console.WriteLine("Value of c is {0}", c);
c = a / b;
Console.WriteLine("Value of c is {0}", c);
c = a % b;
Console.WriteLine("Value of c is {0}", c);
c = a++;
Console.WriteLine("Value of c is {0}", c);
c = a--;
Console.WriteLine("Value of c is {0}", c);
Console.ReadLine();
}
}
}输出结果
Value of c is 132 Value of c is 66 Value of c is 3267 Value of c is 3 Value of c is 0 Value of c is 99 Value of c is 100