|
-
Jul 5th, 2008, 04:24 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2.0] make a variable only accessable by the class it is in?
I have a class formatted like below
Code:
class MyDll
{
class A_SubClass
{
public string A = "Access Me";
public string B = "Access Me";
public string z = "Don't Access Me";
}
class B_SubClass
{
public string A = new A_SubClass().z;
}
}
I want to have it so when using the dll I can't access "z" but I can access "z" from "B_SubClass" inside the dll.
Last edited by high6; Jul 5th, 2008 at 04:30 PM.
-
Jul 5th, 2008, 05:09 PM
#2
Re: [2.0] make a variable only accessable by the class it is in?
The "internal" modifier allows access to the variable only within the same assembly. I think that's what you are looking for.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 5th, 2008, 06:37 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] make a variable only accessable by the class it is in?
 Originally Posted by crptcblade
The "internal" modifier allows access to the variable only within the same assembly. I think that's what you are looking for.
when using the dll does it still show up in the auto-complete list?
-
Jul 5th, 2008, 09:14 PM
#4
Re: [2.0] make a variable only accessable by the class it is in?
As far as a client is concerned, any types or members declared 'internal' in a referenced assembly do not exist. 'internal' is to assemblies as 'private' is to types. A private member only exists within the type it's declared in. Likewise internal members or type only exist within the assembly they're declared in.
There are various examples of internal members in the Framework itself. Consider the DataRow class. You cannot create a DataRow object using the 'new' key word. How do you suppose that is achieved? How is it that a DataTable can create a DataRow when you call its NewRow method but you can't create one yourself? That's because the DataRow constructor is declared internal. Your client code cannot see it because it doesn't exist outside the System.Data.dll assembly, but the DataTable class is declared in that assembly too, so it can invoke the DataRow constructor.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|