C # Accessibility Consistency inconsistencies

Source: Internet
Author: User

The reason, one of which is that the access level of the return parameter is less than the access level of the function, that is, when you define a method that returns a parameter, if the access level of the returned parameter is lower than the access level of the method, this error is understandable, if the returned parameter cannot be accessed, The returned method of the definition is also incorrect. (When you use a custom type in a Field/property/method with a more accessible (for example, public), this problem occurs when the type is less accessible (for example, protected/private))

Then: Each type referenced in the formal parameter list of the return type and method must have at least the same accessibility as the method itself

For example:

public class ClassA

{

Private Class SUBCLASSB

{              ...          }

Public SUBCLASSB INSTANCEOFB;

}

In this case, there is an error of access inconsistency, when others use ClassA, INSTANCEOFB field because it is public, so it should be available, but its type, SUBCLASSB, but not open, causing conflict.

Workaround: Add public before the type you define to increase its access

C # Accessibility Consistency inconsistencies

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.