Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
initonly indicates that variable assignment can occur only as part of the declaration or in a static constructor in the same class.
All Platforms
Remarks
initonly is a context-sensitive keyword; see Context-Sensitive Keywords for more information.
Windows Runtime
Requirements
Compiler option: /ZW
Common Language Runtime
Requirements
Compiler option: /clr
Examples
Example
// mcpp_initonly.cpp
// compile with: /clr /c
ref struct Y1 {
initonly
static int staticConst1;
initonly
static int staticConst2 = 0;
static Y1() {
staticConst1 = 0;
}
};
See Also
Reference
Classes and Structs (Platform)