नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
'var' : l-value use of initonly static data member is only allowed in the class constructor of class 'class'
Remarks
Static initonly data members can only be used as l-values at their point of declaration, or in a static constructor.
Instance (non-static) initonly data members can only be used as l-values at their point of declaration, or in instance (non-static) constructors.
Example
The following example generates C3894:
// C3894.cpp
// compile with: /clr
ref struct Y1 {
initonly static int data_var = 0;
public:
// class constructor
static Y1() {
data_var = 99; // OK
System::Console::WriteLine("in static constructor");
}
// not the class constructor
Y1(int i) {
data_var = i; // C3894
}
static void Test() {}
};
int main() {
Y1::data_var = 88; // C3894
int i = Y1::data_var;
Y1 ^ MyY1 = gcnew Y1(99);
Y1::Test();
}