What is lazy initialization of objects? How do you do that and what are the advantages?
.net – lazy initialization and why is it useful
.net
Related Question
- C# – Deep cloning objects
- C# – How to enumerate an enum
- C# – What are the correct version numbers for C#
- C# – Why is Dictionary preferred over Hashtable in C#
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- .net – Difference between decimal, float and double in .NET
- C# – Why not inherit from List
Best Solution
Lazy Initialization is a performance optimization where you defer (potentially expensive) object creation until just before you actually need it.
One good example is to not create a database connection up front, but only just before you need to get data from the database.
The key reason for doing this is that (often) you can avoid creating the object completely if you never need it.