Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of protected Internal access specifier in the below code

ok, let me start with an example.This is my base class in another assembly

namespace BL
{
    public class BasicClass
    {
        protected internal void func()
        {
            //Code Logic
        }
    }
}

Now this is my derived class in another assembly

namespace DL
{
    public class DerivedClass:BasicClass
    {
        private void hello()
        {
            func();
        }
    }
}

I'm able to call the func() from base class , hence it shows that the protected access modifier property but what about the internal access modifier property.Should it be allowed to access func() inside another assembly since its declared internal.If so then why call it protected internal and not simple protected

like image 571
iJade Avatar asked Feb 18 '23 04:02

iJade


1 Answers

You might want to give this a read.

The protected internal accessibility level means protected OR internal, not protected AND internal. In other words, a protected internal member can be accessed from any class in the same assembly, including derived classes. To limit accessibility to only derived classes in the same assembly, declare the class itself internal, and declare its members as protected.

like image 113
Steffan Donal Avatar answered Apr 13 '23 00:04

Steffan Donal