473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Private vs Non-Public

Hello All,

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"?

Help is always appreciated. Thanks,

Paul

Jun 14 '06 #1
5 1918
"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/
Jun 14 '06 #2
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:nm********************************@4ax.com...

"protected" and "internal" are the two other non-public visibilities.


Also, "protected internal" is a kind of accessibility, presumably to make it
clear that "private internal," etc., is not allowed.

///ark
Jun 14 '06 #3
"Mark Wilden" <Ma********@newsgroups.nospam> wrote:
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:nm********************************@4ax.com...

"protected" and "internal" are the two other non-public visibilities.


Also, "protected internal" is a kind of accessibility, presumably to make it
clear that "private internal," etc., is not allowed.


Yes, that guy slipped my mind.

-- Barry

--
http://barrkel.blogspot.com/
Jun 14 '06 #4
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:7f********************************@4ax.com...
Also, "protected internal" is a kind of accessibility, presumably to make
it
clear that "private internal," etc., is not allowed.


Yes, that guy slipped my mind.


I've never used protected internal -- have you?
Jun 14 '06 #5
"Mark Wilden" <Ma********@newsgroups.nospam> wrote:
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:7f********************************@4ax.com...
Also, "protected internal" is a kind of accessibility, presumably to make
it
clear that "private internal," etc., is not allowed.


Yes, that guy slipped my mind.


I've never used protected internal -- have you?


I have, but not often. Trivially: it's never more powerful than having
an existing protected method, and then writing an internal method to
forward to the protected method.

The circumstances I've used it appear to mostly be for virtual or
abstract methods that need to be overridden, but shouldn't form part of
the public interface of a class, yet need to be called by other classes
in the same assembly or "eco-system".

One example I have on my disk right now: I had a simple visual tree
framework once (i.e. a hierarchical render tree), and each element in
the visual tree had a Render method which accepted a Renderer argument.
The renderer actually visited the tree, and was the only guy who could
legitimately call the method:

protected internal virtual void Render(Renderer r) { ... }

There were other methods along similar lines, for layout etc. IIRC. It's
been some time since I looked at it; it was an experiment when I first
found out about Avalon, and it never got finished.

-- Barry

--
http://barrkel.blogspot.com/
Jun 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Rubin | last post by:
Is there ever a good reason to declare private non-virtual member functions in a class definition? As far as private virtual function are concerned, my understanding is that, if you have a...
12
by: Will | last post by:
Is it possible to have private instance members in a javascript class? function myObject() { var private = 1; this.getPrivate = function() { return private; } this.incrementPrivate =...
34
by: Andy | last post by:
1) Is there any use of defining a class with a single constructor declared in private scope? I am not asking a about private copy constructors to always force pass/return by reference. 2) Is...
5
by: TomislaW | last post by:
What is the purpose or difference between private static and private method in non-static class?
3
by: Bob Day | last post by:
Ok, I have done a lot of reading(of the newsgroup answers, help files and MSDN articles) of synclock. I understand what you are saying in the newsgroup, and it is very helpful. It does, however,...
23
by: Ben Voigt | last post by:
I have a POD type with a private destructor. There are a whole hierarchy of derived POD types, all meant to be freed using a public member function Destroy in the base class. I get warning C4624....
7
by: Victor | last post by:
I just tried a test comparing a Function to a Private Function with this code: <% Option Explicit dim X1 X1 = 9 Private Function RealTest(here) RealTest = here + X1 End Function
8
by: =?Utf-8?B?RGFuTQ==?= | last post by:
Can someone help with the following problem. I am sending an encrypted SOAP message to a .NET 2.0 + WSE 3.0 web service. When .NET attempts to decrypt the message it cannot read the private key...
11
by: Yarco | last post by:
For example: <?php class Test { private $name = 'yarco'; } $p = new ReflectionPropery('Test', 'name'); print $p->getValue();
8
by: puzzlecracker | last post by:
The statement is taken from FAQ . What about non-virtual functions? Can they be overriden? I still don't see a good justification to prefer private inheritance over composition. In fact, I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.