ตัวดำเนินการที่เพิ่มขึ้น
หากต้องการเพิ่มค่าใน 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);
}
}