2 Replies - 317 Views - Last Post: 18 February 2013 - 08:10 AM Rate Topic: -----

#1 Witchking  Icon User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 188
  • Joined: 17-February 13

Nested classes, constructor arguments

Posted 18 February 2013 - 07:08 AM

I have three classes A, B and C. A will be used as objects in an array of indefinite size. B and C will be used in separate arrays within A and have no meaningful purpose outside A. Now my question is, since classes B and C will never be used outside an instance of A, should i write them as nested classes inside A? What are the benefits of doing or not doing so, if any? As i understand it, a nested class can not be instantiated by any, but the nesting class?


public ThisIsAClass(char t, string n) //constructor method
{
    var1 = t;
    var2 = n;
}
Does the method accept null as an argument? If not, how can i change it to do so for the second and only the second argument?

Is This A Good Question/Topic? 0
  • +

Replies To: Nested classes, constructor arguments

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5480
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Nested classes, constructor arguments

Posted 18 February 2013 - 08:10 AM

Tutorial on classes linked in my signature block
Was This Post Helpful? 0
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Nested classes, constructor arguments

Posted 18 February 2013 - 08:10 AM

To answer your second question, String is a reference type thus you can set it to null. Char is a value type so it can't be null.

As for your first question, I use nested classes all the time (as does the .NET library) and they can be instantiated by other code, it all depends on the protection level you've set (public nested classes in a public class are fully visible). Nested classes have access to the private and protected members of the containing class (if they have a reference to it, that is). Depending on what you are doing, that may or may not be important to you. Read this page for more information.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1