Skip to content

Latest commit

 

History

History
61 lines (56 loc) · 1.21 KB

File metadata and controls

61 lines (56 loc) · 1.21 KB
title initonly (C++/CLI) | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic article
f1_keywords
initonly_cpp
initonly
dev_langs
C++
helpviewer_keywords
initonly attribute [C++]
ms.assetid f745d7fa-dc08-46f1-9b97-0977be58a008
caps.latest.revision 16
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
ru-ru
zh-cn
zh-tw
translation.priority.mt
cs-cz
pl-pl
pt-br
tr-tr

initonly (C++/CLI)

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.

The following example shows how to use initionly:

// 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

Classes and Structs