C # access levels

Often encounter problems examine levels of access in the interview process, today one-time settlement.

A, public access is not limited directly to remember just fine. 

Two, private private, accessible only within the class, this has nothing to say directly to remember just fine.

Three, internal assembly can be accessed with a nothing to do with namespaces , we have to verify:

       First, prepare a class:

namespace Algorithm
{
    //测试访问级别
    public abstract class Visit
    {
        private void private_Add() { }
        public void public_Add() { }
        internal void internal_Add() { }
        protected void protected_Add() { }
        internal protected void internal_protected_Add() { }
    }
}

It was checked by different assemblies:

 

 Fourth, internal and protected in the derived class can access the class, this is not to limit the assembly , though not wrong when in use, but confusing in the written test, there are wood ah

 

Five, internal protected, while increasing both modifiers, this time is taken corpus , and not set, Look below:

 

 

 Summary: Learn C # member access level is designed to allow us to use modifier reasonable, the frequency of the interview process appear very high, knocking over code manually stronger than memorizing it.

 

Guess you like

Origin www.cnblogs.com/heweijian/p/12593358.html