Common C # Compiler Errors

Source: Internet
Author: User

1. compiler error cs1527

Updated: February 1, November 2007

Error Message
Elements defined in the namespace cannot be explicitly declared as private, protected, or protected internal.

The type declaration in the namespace can have public or internal access. If no accessibility is specified, the default value is internal.

The following example generates cs1527:

CopyCode
// Cs1527.cs
Namespace sample
{
Private Class C1 {}; // cs1527
Protected Class C2 {}; // cs1527
Protected internal Class C3 {}; // cs1527
}

2. compiler error cs1597

Updated: February 1, November 2007

Error Message
The semicolon following the method or access block is invalid.

You do not need to (or are not allowed) Use a semicolon to end the method or access the block.

The following example generates cs1597:

Copy code
// Cs1597.cs
Class testclass
{
Public static void main ()
{
}; // Cs1597, remove semicolon
}

----------------------------------------
However, you can end the class and namespace with a semicolon.
For example:

Class testclass
{
Public static void main ()
{
}
};

 

3. compiler error cs0542

Updated: February 1, November 2007

Error Message
"User-defined type": the member names cannot be the same as their closed type

A name is used multiple times in the same constructor.The cause of this error may be that the returned type is put in the constructor due to negligence. (That is to say, the constructor cannot have a return type.)

The following example generates cs0542:

Copy code
// Cs0542.cs
Class F
{
// Remove void from F () to resolve the problem.
Void F () // cs0542, same name as the class
{
}
}

Class myclass
{
Public static void main ()
{
}
} If your class is named "item" and an index is declared as this, you may encounter this error. In the issued Code, the default indexer name is

"Item", resulting in a conflict.

Copy code
// Cs0542b. CS
Class item
{
Public int this [int I] // cs0542
{
Get
{
Return 0;
}
}
}

Class cmain
{
Public static void main ()
{
}
}

 

 

To be continued ......

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.