Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2005, 6:53 PM   #1
Arla
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 223
Rep Power: 4 Arla is on a distinguished road
Nested Classes Question - Solved

Okay, so say I have the following

class TestClass
{
  public string stringa
  class NestedClass
  {
    public string stringb
  }
}

If I declare a variable as TestClass, can I access both the NestedClass variables and the TestClass variables, or do I need to specify both a variable for TestClass and a variable for TestClass.NestedClass? (hope that makes some sense)

Last edited by Arla; Apr 7th, 2005 at 5:26 PM. Reason: Solved
Arla is offline   Reply With Quote
Old Apr 7th, 2005, 4:05 PM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
nope. You need to actually have an instance of NestedClass within TestClass, like this:

class TestClass
{
  public string stringa
  class NestedClass
  {
    public string stringb
  }
  public NestedClass nc;
}
Then if you had an instance of TestClass called "tc", you could do things like:
tc.nc.stringb="Foo";
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:06 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC