protected internal method on an abstract base class

S

ssg31415926

I have an abstract base class from which has concrete subclasses. I
have a method on the base class marked as 'protected internal'.

I have another class in the same assembly which holds a reference to an
instance of one subclass. I don't seem to be able to see the protected
internal method. Should I? If not, why not? (If I add a protected
internal method to the subclass, I can access it.)
 
J

Jon Skeet [C# MVP]

ssg31415926 said:
I have an abstract base class from which has concrete subclasses. I
have a method on the base class marked as 'protected internal'.

I have another class in the same assembly which holds a reference to an
instance of one subclass. I don't seem to be able to see the protected
internal method. Should I? If not, why not?

Could you post a short but complete program which demonstrates the
problem? It sounds like it should be okay.

See http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
the above.

Jon
 
S

Stoitcho Goutsev \(100\)

Hi,

Yes you should be able to access the method.

Here is a sample for a console application build by the your explanation or
at least how I understand them. It works fine

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FooBar fb = new FooBar();
fb.Bar();

}

}

public abstract class Foo
{
protected internal void Bar()
{
Console.WriteLine("Bar");
}

}
public class FooBar : Foo
{
}


}
 
S

ssg31415926

Er, whoops! I have to admit to a bit of carelessness. I had two very
similarly-named methods (there's a lesson there, I think!) and, well, I
guess I don't have to spell it out, do I. Thanks for your replies -
they made me look at the code again and it was then I realised what I'd
done.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top