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
(if 2, this is not an attempt to complain about it - I just want to understand)
Class, record, and struct member accessibility However, a public member of an internal class might be accessible from outside the assembly if the member implements interface methods or overrides virtual methods that are defined in a public base class.
A public member of a class or struct is a member that is accessible to anything that can access the containing type. So a public member of an internal class is effectively internal.
Internal is only available within the assembly it resides in. Public is available to any assembly referencing the one it resides in. If you can access the internal class from another assembly you either have "InternalsVisibleTo" set up, or you're not referencing the class you think you are.
Internal members are listed as part of the Company Directory, can be added to multiple workspaces at one time, and can view items marked "Internal." Internal Members are generally people within your company. External Members are generally customers, clients, partners, vendors, etc.
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".
To me that means "the accessibility domain of C is restricted to this assembly; the accessibility domain of M is the unrestricted subset of the accessibility domain of its container, C".
"public" means that to me because that's what the specification says it means. I encourage you to read the portion of the specification which covers accessibility domains if you have questions or concerns about this.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With