"Paul" <he********@yahoo.ca> wrote:
I am new to C# and dot NET in general. The book I am reading uses the
term "non-public."
I suspect that they don't mean "private", otherwise they would have
said so. What is the difference between "non-public" and "private"?
"protected" and "internal" are the two other non-public visibilities.
"internal" members and types are visible only to other types in the same
assembly (i.e. same .exe file or same .dll file). When you declare a
class without any visibility specifier, it means the class is internal,
for example. Class members without a visibility specifier are private,
however. Internal is useful to allow two classes in a class library to
communicate with each other, and simultaneously prevent end-user code
from interfering with this communication (because the methods etc. in
question would be marked internal, and wouldn't be available outside the
assembly).
"protected" members are visible only within the type and its
descendants. This allows special communication along the inheritance
hierarchy, but disallows "outsider" class access.
Note that if a constructor for a non-sealed class which declares the
"protected" members is public or protected, then any descendant can
derive from it, and so "protected" in that case doesn't act as any kind
of "security" mechanism for classes that live in class libraries. For
this reason, protected members require just as much care and parameter
error checking as public members (if not more care).
-- Barry
--
http://barrkel.blogspot.com/