0

I understand what protected internal actually is but I'm confused as to why you would use it. It looks like protected internal and internal have essentially the same protection levels. From my understanding if I wanted to access a variable from a non-derived class in the same assembly this would work with internal and protected internal but not protected. If the variable was in a non derived class in a different assembly this would not work with internal or internal protected or protected. It seems like anything I could want from a protected internal access specifier I will get from the internal specifier. When is it it useful to use protected internal over internal ?

edit : not sure how this is a duplicate - i'm not asking anyone to define protected internal for me, im looking for clarification on why it would be used over the internal modifier. If the reason you think i'm asking this question is because i don't fully understand what protected internal means could you identify where my understanding is flawed?

  • I thought protected internal meant members are only visible to classes that derive from the class OR are in the same assembly. They will still be accessible in a non derived class in the same assembly due to the internal side of the access specifier so how is internals visibility any different from protected internal? The only way I could see it being useful is if there is a way for a class to inherit from another class outside of its own assembly which I is a concept I haven't met yet. – anonymous2506 May 13 '17 at 15:33
  • 1
    FWIW, I have never used (or seen) `protected internal` and I can't come up with a reasonable use case for it either. – BJ Myers May 13 '17 at 17:28
  • 1
    Hi, You're another victim of the aggressive duplicate rules here. You can derive your answer from the alleged duplicate but people don't realise that isn't always easy for novices. Protected Internal can be accessed from a derived class OR other classes in the same assembly. It's a way of only letting a derived classes have access without restricting access within the assembly implementation. – Persixty May 14 '17 at 09:48
  • 1
    "The only way I could see it being useful is if there is a way for a class to inherit from another class outside of its own assembly" Yes, there is (consider if you extend a class from the .Net framework in your own code; alternatively you can create two projects in one solution and refer to one from the other). So `protected internal` is basically saying "you won't need this in the 'outside world' *unless* you're going to derive a new class from it". As other commenters have said, it's a rare thing to want in practice. – Matthew Strawbridge May 14 '17 at 17:21
  • ah ok that makes sense, thanks Matthew. – anonymous2506 May 14 '17 at 17:54

0 Answers0