C# 中的增量(++)和减量(--)运算符是什么?
增量运算符
若要增量 C# 中的某个值,可以使用增量运算符,即前增量和后增量运算符。
以下是一个示例 -
示例
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# 中的某个值,可以使用减量运算符,即前减量和后减量运算符。
以下是一个示例 -
示例
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);
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP