Mechanism of youyuan in C #

Source: Internet
Author: User

Is there any mechanism for youyuan in the C # language?
Is there a way to expose some internal members of a class to only one other class?

A:

C # There are no friends functions and friends class. In C ++, the user meta function and user Meta class are not necessary. They are used to improve efficiency (accessing internal members is faster than accessing external members, so encapsulation is not considered, (c) With the improvement of hardware performance, the role of youyuan is insignificant, but it destroys the class encapsulation, so this feature is removed in Java, C # also removes this feature.

This design of the hosting environment should also have its own principle, which can eliminate unnecessary coupling and break the class encapsulation. Youyuan is against Oo, and the hosting environment il does not support

Internal. This attribute indicates that the class and Members can only be used in the current program. In some ways, they are similar to friends.

Class friends, function friends are generally not used, can be replaced by public, and then encapsulated in the Assembly with internal, but friends can be used in the assembly, therefore, C #2.0 adds this function (implemented using attribute)

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.