Error finding mechanism of constructor in C #

Source: Internet
Author: User
Tags hhg

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.