8.10. Understanding Lazy Object Instantiation

NOTE

This section assumes you are comfortable with the topics of .NET generics and .NET delegates. If that's not the case, you may want to return to this section once you have completed Chapters 10 and 11.

When you are creating classes, you may occasionally need to account for a particular member variable in code, which may never actually be needed, in that the object user may not call the method (or property) that makes use of it. Fair enough. However, this can be very problematic if the member variable in question requires a large amount of memory to be instantiated.

For example, assume you are writing a class that encapsulates the operations of a digital music player. In addition to the expected ...

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.