Prev | Current Page 101 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"


Supported interfaces are listed in the same way as they are for classes, in a base
interface list after the structure identifier. Generally, supporting interfaces for structures is the
same as supporting interfaces for classes. Chapter 6 covers interfaces in detail. Implementing
interfaces on structures has performance implications; specifically, it incurs a boxing operation
to call methods through an interface reference on the structure value instances.
CHAPTER 3 n CLASSES AND STRUCTURES 51
Boxing and Unboxing
All types within the CLR fall into one of two categories: reference types (objects) or value types
(values). You define objects using classes, and you define values using structures. A clear
divide exists between these two. Objects live on the memory heap and are managed by the
garbage collector. Values normally live in temporary storage spaces, such as on the stack. The
one notable exception already mentioned is that a value type can live on the heap as long as it
is contained as a field within an object. However, it is not autonomous, and the GC doesn??™t
control its lifetime directly. Consider the following code:
Public Class EntryPoint
Shared Sub Print(ByVal obj As Object)
System.Console.WriteLine("{0}", obj.ToString())
End Sub
Shared Sub Main()
Dim x As Integer = 42
Print(x)
End Sub
End Class
It looks simple enough.


Pages:
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
dieta light życzenia urodzinowe pozycjonowanie Tango Olsztyn Unibet