Search code examples
c#classinternal

What is the meaning of a public member of an internal class?


For example:

internal class C
{
    public void M()
    {
        Console.WriteLine("foo");
    }
}

To me, that reads "a method that can be accessed by anyone, regardless of assembly living inside a class that can only be accessed from code in the same assembly".

My experience with the compiler tells me that if I do something like that and do not get a warning, there is probably a valid reason to have it.

So, I suppose either

  1. Something is lacking in my understanding of protection levels.
  2. There could be a warning but there isn't one.

(if 2, this is not an attempt to complain about it - I just want to understand)


Solution

  • See this SO Question for a detailed answer on how it functions.

    In my experience, I like to mark internal members public in anticipation of a future time when I want to change the scope of the class to public. This way I can do that and all the previously marked internal methods are automatically public.