什么是C#中的增量(++)和减量(-)运算符?
增量运算符
要递增C#中的值,可以使用递增运算符,即Pre-Increment和Post-Increment运算符。
以下是一个例子-
示例
using System;
class Demo {
static void Main() {
int a = 250;
Console.WriteLine(a);
a++;
Console.WriteLine(a);
++a;
Console.WriteLine(a);
int b = 0;
b = a++;
Console.WriteLine(b);
Console.WriteLine(a);
b = ++a;
Console.WriteLine(b);
Console.WriteLine(a);
}
}递减运算符
要递减C#中的值,可以使用递减运算符,即Pre-Decrement和Post-Decrement运算符。
以下是一个例子-
示例
using System;
class Demo {
static void Main() {
int a = 250;
Console.WriteLine(a);
a--;
Console.WriteLine(a);
--a;
Console.WriteLine(a);
int b = 0;
b = a--;
Console.WriteLine(b);
Console.WriteLine(a);
b = --a;
Console.WriteLine(b);
Console.WriteLine(a);
}
}热门推荐
10 简短的宝宝出生祝福语
11 收围巾的祝福语简短
12 老公生日祝福语简短好看
13 简短佛教新年祝福语大全
14 生日哥哥祝福语简短独特
15 庆祝国家的祝福语简短
16 小孩想说的祝福语简短
17 祝产妇的祝福语简短
18 亲戚送行祝福语简短精辟