PC Review


Reply
Thread Tools Rate Thread

Class private to a namespace

 
 
JamesO
Guest
Posts: n/a
 
      10th Feb 2007
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      10th Feb 2007
JamesO wrote:
> 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
 
Reply With Quote
 
j1mb0jay
Guest
Posts: n/a
 
      11th Feb 2007
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.
--
Regards JJ (UWA)

"JamesO" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      11th Feb 2007
j1mb0jay <(E-Mail Removed)> wrote:
> 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).

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
RobinS
Guest
Posts: n/a
 
      11th Feb 2007

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> j1mb0jay <(E-Mail Removed)> wrote:
>> 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).
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


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.



 
Reply With Quote
 
RobinS
Guest
Posts: n/a
 
      11th Feb 2007

"RobinS" <(E-Mail Removed)> wrote in message
news:eMmdnSxhM6Li-(E-Mail Removed)...
>
> "Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> j1mb0jay <(E-Mail Removed)> wrote:
>>> 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).
>>
>> --
>> Jon Skeet - <(E-Mail Removed)>
>> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
>> If replying to the group, please do not mail me too

>
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The type or namespace name 'Generic' does not exist in the class or namespace 'System.Collections' pantagruel Microsoft C# .NET 1 23rd Oct 2007 12:07 AM
The type or namespace 'Installer' does not exist in the class or namespace 'System.Configuration' John Chrisman Microsoft C# .NET 2 18th Nov 2005 11:24 PM
The type or namespace name 'blah' does not exist in the class or namespace 'abc.def' WineNCheese Microsoft Dot NET Framework 3 22nd Apr 2005 12:47 AM
Private Namespace in VB.NET Joshua Frank Microsoft Dot NET Framework 6 29th Sep 2004 06:52 PM
The type or namespace name 'Windows' does not exist in the class or namespace 'System' (are you missing an assembly reference?) =?Utf-8?B?UmF5?= Microsoft Dot NET 1 7th Apr 2004 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.