In the constructor: this (...) Use

Source: Internet
Author: User

: This (...)
• One constructor can call another constructor.
Struct ColouredPoint
{
Public ColouredPoint (int x, int y)
: This (x, y, Colour. Red)
{
}
 
Public ColouredPoint (int x, int y, Colour c)
{
...
}
...
Private int x, y; www.2cto.com
Private Colour c;
}
There is always a public default constructor declared by the compiler. Whether you declare a constructor or not, the public default constructor declared by the compiler always exists. Therefore, you cannot define the default constructor, so two default constructor will appear, which is not allowed. However, it should be noted that this is only applicable to structures and is not applicable to classes. The default access permission of the User-Defined constructor of the structure class is private, which is the same as that of the structure class field.
C # You cannot declare a function with the same name as the constructor.

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.