initonly (C++/CLI)

initonly ist ein kontextabhängiger Schlüsselwort (keyword), der angibt, dass die Variablezuweisung nur als Teil der Deklaration oder in einem statischen Konstruktor in derselben Klasse auftreten kann.

Das folgende Beispiel zeigt die Verwendung von initionly:

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

   initonly
   static int staticConst2 = 0;

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

Siehe auch

Klassen und Strukturen