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?
Nested classes, constructor arguments
Page 1 of 12 Replies - 118 Views - Last Post: 18 February 2013 - 08:10 AM
#1
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?
Replies To: Nested classes, constructor arguments
#2
Re: Nested classes, constructor arguments
Posted 18 February 2013 - 08:10 AM
Tutorial on classes linked in my signature block
#3
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|