Nested Classes

You can organize classes within other classes. The following code snippet shows how you can define a nested class:

image

Nested classes can also be marked as Private, and this is the only situation in which the qualifier is enabled. If you make a class private, you cannot use that class outside the class that defines it. Continuing with the preceding example, if the NestedClass class were marked as Private, you could use it only within the Test class. If a nested class is not private, you can invoke it the usual way; you need to write the full name of the class as follows:

Dim nc As New Test.NestedClass

Typically, classes are organized within namespaces (as described in Chapter 9, “Organizing Types Within Namespaces”), but there can be situations in which you need to organize small frameworks of classes, and then nested classes can be a good solution.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.169.40