What is lazy initialization of objects? How do you do that and what are the advantages?
In general computing terms, 'lazy evaluation' means to defer the processing on something until you actually need it. The main idea being that you can sometimes avoid costly operations if you turn out to not need it, or if the value would change before you use it.
A simple example of this is System.Exception.StackTrace. This is a string property on an exception, but it isn't actually built until you access it. Internally it does something like:
String StackTrace{
get{
if(_stackTrace==null){
_stackTrace = buildStackTrace();
}
return _stackTrace;
}
}
This saves you the overhead of actually calling buildStackTrace until someone wants to see what it is.
Properties are one way to simply provide this type of behavior.