Example code of the error code returned by the constructor:
Struct HHG
{
HHG (int tothegalhg)
{
Question = 9*6; 1
...
}
String cover = "Don't Panic"; 2
Static const int answer = 42; 3
Const Hiker arthur = new Hiker (); 4
Const int question; 5
...
}
Error of 1st statements: constants cannot be initialized in constructors. constants can only be initialized during declaration.
Error of the 2nd statements: initialization cannot be performed when the instance field is declared in the structure, but can be performed in the class.
Error in 3rd statements: the constant field cannot be explicitly declared as static, and the constant field can only be implicitly declared as static.
4th statement errors: constant fields can only be used for simple types, enumerations, and strings.
Error in 5th statements: the constant field is not initialized during declaration.
Constant field definition: www.2cto.com
The secret is implicitly static.
The token must be initialized during declaration.
Compile must be initialized as a compilation constant value.
A string can be a constant only for simple type and enumeration.
Author: ershouyage