Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

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);
   }
}