Prabhakaran Parthipan
Prabhakaran Parthipan

Reputation: 4273

Why protected internal class cannot derive?

Scope of the protected internal is same assembly, or by any derived class in another assembly.Then Why protected internal class cannot derive?

Sample code:

 protected internal class AbsClass
    {
        int m = 50;
        public int am = 5;     

        public void nonAbsfn()
        {
            Console.WriteLine(m + am);
        }
    }

    class TestAbstract : AbsClass
    {


    }

Upvotes: 0

Views: 188

Answers (2)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174289

A class can only be protected internal if it is an inner class.
Otherwise, a class can only be public or internal.

To fix your compilation error, make the class either public or internal. The error you are getting has nothing to do with the derived class TestAbstract.

Upvotes: 5

NeddySpaghetti
NeddySpaghetti

Reputation: 13495

According to the MSDN documentation:

The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

So you should be able to do it. Can you post some of your code?

Upvotes: 0

Related Questions