Delen via


initonly (C++/CLI)

initonly is een contextgevoelig trefwoord dat aangeeft dat variabele toewijzing alleen kan plaatsvinden als onderdeel van de declaratie of in een statische constructor in dezelfde klasse.

In het volgende voorbeeld ziet u hoe u initionlygebruikt:

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

   initonly
   static int staticConst2 = 0;

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

Zie ook

Klassen en Structs