C#中的数字
对于C#中的数字,请使用int类型。它代表一个整数,它是正整数或负整数。
让我们看看如何在C#中使用数学运算符+将两个整数相加-
using System;
using System.Linq;
class Program {
static void Main() {
int x = 20;
int y = 30;
int sum = 0;
sum = x + y;
Console.WriteLine(sum);
}
}现在让我们了解这些数学运算符的顺序,即运算符的优先级。
运算符优先级确定表达式中术语的分组。这会影响表达式的计算。某些运算符的优先级高于其他运算符;例如,乘法运算符的优先级高于加法运算符。
例如x=9+2*5;在这里,x被赋值为19,而不是55,因为运算符*的优先级高于+,所以第一次评估发生在2*5上,然后将9添加到它。
以下是显示运算符顺序的示例-
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 200;
int b = 100;
int c = 150;
int d = 50;
int res;
res = (a + b) * c / d;
Console.WriteLine("Value of (a + b) * c / d is : {0}", res);
res = ((a + b) * c) / d;
Console.WriteLine("Value of ((a + b) * c) / d is : {0}", res);
res = (a + b) * (c / d);
Console.WriteLine("Value of (a + b) * (c / d) : {0}",res);
res = a + (b * c) / d;
Console.WriteLine("Value of a + (b * c) / d : {0}",res);
Console.ReadLine();
}
}
}热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下