[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.
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.
Re: [2.0] make a variable only accessable by the class it is in?
Quote:
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?
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.