CSharp · Console
using System;
// http://stackoverflow.com/questions/26109120/when-an-instance-of-a-class-is-returned-do-all-properties-get-returned
public static class Go
{
public static void Main()
{
var customer = new Customer();
Console.WriteLine("First get. Result: {0}", customer.CustAcct);
Console.WriteLine("Second get. Result: {0}", customer.CustAcct);
}
}
public class Customer
{
private double ? _custAcct = null;
public double CustAcct
{
get
{
if (!_custAcct.HasValue)
{
_custAcct = GetCustAcct();
}
return _custAcct.Value;
}
}
private double GetCustAcct()
{
// do something that takes a long time
Console.WriteLine("Something is taking a long time");
return 1234.45;
}
}