다음을 통해 공유


initonly

initonly is a context-sensitive keyword that indicates that variable assignment can occur only as part of the declaration or in a static constructor in the same class.

다음 예제에서는 initionly의 사용 방법을 보여 줍니다.

// mcpp_initonly.cpp
// compile with: /clr /c
ref struct Y1 {
   initonly
   static int staticConst1;

   initonly
   static int staticConst2 = 0;

   static Y1() {
      staticConst1 = 0;
   }
};

참고 항목

참조

클래스 및 구조체 (관리)