Prev | Current Page 381 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Additionally, placeholder identifiers conventionally make the first letter a
capital T to denote it as a type. Naming conventions like these, similar to the naming convention
where interface names start with a capital I, provide for code that is generally easier to
read. Generic type definitions commonly use type parameters such as T for type, K for keys,
and V for values.
Generic Type Definitions and Constructed Types
As touched upon previously, a generic type is a compiled type that is unusable until a closed
type is created from it. A nongeneric type is also known as a closed type, whereas a generic
type is known as an open type. However, it is possible to define a new open type via a generic,
as the following code shows:
Public Class A(Of T)
Private innerObject As T
End Class
Public Class Consumer(Of T)
Private obj As A(Of Stack(Of T))
End Class
In this case, a generic type, Consumer(Of T), is defined and also contains a field that is
based on another generic type. When declaring the type of the Consumer(Of T).obj field,
A(Stack(Of T)) remains open until someone declares a constructed type based on
Consumer(Of T), thus creating a closed type for the contained field.
CHAPTER 12 n GENERICS 240
Generic Classes and Structures
So far, all of the examples have shown generic classes, but overall, the rules of generics map
equally to structures.


Pages:
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
zakłady bukmacherskie Wczasy nad morzem oferty spa Spa Ciechocinek kolokacja rack