Class private to a namespace

J

JamesO

Hello all,

Is there a way to make a class private to the namespace so that other
classes in the namespace can see and use it but noone outside a namespace
can see or use it?

Feel free to send me to links to read, I just cannot seem to find anything
about this, maybe it's not possible.

Thanks in advance, jmy
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

JamesO said:
Is there a way to make a class private to the namespace so that other
classes in the namespace can see and use it but noone outside a namespace
can see or use it?

Use a convention one namespace = one assembly and use internal
access modifier.

Arne
 
J

j1mb0jay

Access Modifiers for classes

public - class visible everywhere.
default - only access from same package.

These are the only two options I am aware of for a class, I'm sure the
protected modifier is only available for methods and attributes.
 
J

Jon Skeet [C# MVP]

j1mb0jay said:
Access Modifiers for classes

public - class visible everywhere.
default - only access from same package.

No, that's "access from same assembly". It's equivalent to writing
"internal". .NET has no notion of package-level access. (.NET doesn't
have packages, either - Java does, and there the default is indeed
package access.)
These are the only two options I am aware of for a class, I'm sure the
protected modifier is only available for methods and attributes.

Private and protected are available for nested types (and private is
the default in that situation).
 
R

RobinS

Jon Skeet said:
No, that's "access from same assembly". It's equivalent to writing
"internal". .NET has no notion of package-level access. (.NET doesn't
have packages, either - Java does, and there the default is indeed
package access.)


Private and protected are available for nested types (and private is
the default in that situation).

Here's some definition for the OP. This is from Tim Patrick's
"Start-to-Finish VB2005" book. I think that he's looking for is "Friend".

Public -- available everywhere. You can write an app or component that
exposes its types to code beyond itself.

Private -- private variables can be used by any member or procedure w/i the
type. Each instance of a class contains its own version of the variable. If
you derive a new class from a base class that includes a private variable,
the code in that derived class will have no access at all to that Private
variable.

Protected -- like Private, but code in derived classes can also access
them. You can only use this keyword in a class definition, not a structure
or a module.

Friend -- Private to an assembly. They can be used by any code in their
related class/type, but also by any code anywhere in the same assembly.

ProtectedFriend -- Can only be used in classes. Combines all features of
Friend and Protected.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
R

RobinS

RobinS said:
Here's some definition for the OP. This is from Tim Patrick's
"Start-to-Finish VB2005" book. I think that he's looking for is "Friend".

Public -- available everywhere. You can write an app or component that
exposes its types to code beyond itself.

Private -- private variables can be used by any member or procedure w/i
the type. Each instance of a class contains its own version of the
variable. If you derive a new class from a base class that includes a
private variable, the code in that derived class will have no access at
all to that Private variable.

Protected -- like Private, but code in derived classes can also access
them. You can only use this keyword in a class definition, not a
structure or a module.

Friend -- Private to an assembly. They can be used by any code in their
related class/type, but also by any code anywhere in the same assembly.

ProtectedFriend -- Can only be used in classes. Combines all features of
Friend and Protected.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.

Oops, sorry, didn't realize I was posting this in the C# group. I think
Friend is called [internal], and ProtectedFriend is [protected internal]

Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top