Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


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

initonly is a context-sensitive keyword; see Context-Sensitive Keywords for more information.

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

   static int staticConst2 = 0;

   static Y1() {
      staticConst1 = 0;

Community Additions

© 2015 Microsoft