Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] make a variable only accessable by the class it is in?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

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

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    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?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width