什麼是 C# 中的字尾運算子?


自增運算子是 ++ 運算子。如果作為變數的字尾使用,則先返回變數的值,再將其遞增 1。這稱為字尾自增運算子。同樣,自減運算子也有作用,但它會遞減 1。

例如,

a++;

以下示例演示如何使用字尾運算子 -

示例

 線上演示

using System;

class Program {
   static void Main() {
      int a, b;

      a = 10;
      Console.WriteLine(a++);
   
      b = a;
      Console.WriteLine(a);
      Console.WriteLine(b);
   }
}

輸出

10
11
11

更新於: 2020-06-20

709 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始吧
廣告
© . All rights reserved.