Nested Types

 <  Day Day Up  >  

All types except for modules may be declared within another type. A type defined within another type is called a nested type . To refer to a nested type from outside the type it is declared in, you must qualify the type name with the outer type's name .

 Class Customer   Class FullAddress     Public Street As String     Public City As String     Public State As String     Public ZIP As Integer   End Class   Public Name As String   Public Address As FullAddress End Class 

In this example, the address of a customer is stored in a FullAddress type that is declared within the Customer type. It could be used in the following way.

 Dim Address As Customer.FullAddress Dim Customer As Customer Address = New Customer.FullAddress() Address.Street = "134 Main Street" Address.City = "Tulsa" Address.State = "OK" Address.ZIP = 19348 Customer = New Customer() Customer.Name = "John Doe" Customer.Address = Address 

Nested types are most commonly used for helper types that are used only within a type.

Advanced

Nested types differ from inner types in languages such as Java. An instance of a nested type does not automatically contain an instance of its containing type.


 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net