C # Difficulty one by one (5): Class access type

Source: Internet
Author: User
Speaking of the differences between the four classes, it is necessary to explain a concept: an assembly. An assembly (Assembly), which can be simply understood as a. dll or. exe file generated after compilation, is a logical organization of the class library relative to namespace, which can be called the physical organization of the Program Class Library, described on MSDN as " Assemblies contain metadata that describes their own build numbers and the details of all the data and object types they contain. " A general scenario is that an assembly can contain one or more namespaces.

Public: Any method of any other class is visible;
Private: Members defined in this class are accessible only to methods of this class;
Protected: Members of this class can only access the methods of this class and the methods of inheriting classes of this class;
Internal: Members of this class are accessed only by methods of any class in the assembly in which the class is located;
Protected internal: For the protected and internal of the same set.
Therefore from the access level from high to low should be public>protected internal>internal>protected>private

The default modifier for a class is internal, and the default modifier for a member variable in a class is private,namespace, which can be considered a modifier public. Another point on MSDN also mentions that the access level of an inherited class cannot be greater than the access level of the inherited class, such as a class that internal cannot inherit from private.

Using System; /****************************** * chapter:c# Difficulty one by one (v) * Author: Wang Hongjian * date:2010-1-15 * blog:http://www.51obj.cn/* Email: walkingp@126.com * Description: Access modifier * ***************************/namespace Testmain {public class A {public void Aler T () {}} internal class B:a {internal new void Alert () {Console.WriteLine ("You"),}} class program {static void Main ( ) {b b=new B (); B.alert ();}} }

The above is the C # difficulty one by one (5): class type of access content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.