November 2002
Intermediate to advanced
560 pages
11h 16m
English
When considering the use of interfaces on a value type, often the first question asked is, “Can value types support interfaces?” The simple answer is yes; you can call the methods defined in the interface directly on the value type without incurring any overhead. The situation is different, however, if you call the methods through an interface reference. An interface references objects allocated on the garbage collected heap, and value types are normally allocated on the stack—so how does this work? The answer is a familiar one: boxing.
Listing 2.9 demonstrates the use of events and properties in a user-defined interface, IPoint. This interface is implemented by a value type, Point, and an object type, ...
Read now
Unlock full access