People need to be careful with the publicÂ keyword. public in C# is not equivalentÂ to public in C++! In C++, it means “internal to my compilation unit.” In C#, it means what extern meant in C++ (i.e., everybody can call it). This is a huge difference!
This was best said by Krzysztof Cwalina, quoted in the revisedÂ Fourth Edition of The C# Programming Language.Â It actually makes more sense to me know when I browse the .NET Framework source code as to why I see Microsoft using internalÂ access modifiers quite a bit more often. If you are rusty and don’t quite remember the access modifiers they are:
Access not limited.
Access limited to this class or classes derived from this class.
Access limited to this program.
Access limited to this program or classes derived from this class.
Access limited to this class.
But remember, as Christian Nagel said it best, that internal is rather best described as being “access limited to this assembly”, because a program can be defined as a collection of executables and assemblies, and a class marked as internal cannot be accessed by an assembly referencing it.