Let's say I have a class called Customer
with some properties:
public class Customer
{
public string CustAddr = GetCustAddr(); //Long procedure returning address
public double CustAcct = GetCustAcct(); //Long procedure returning account
public string CustInvoice = GetCustInvoice(); //Long procedure returning invoice
}
This class is returned via a function:
public Customer GetData(string query)
{
Customer cust = new Customer();
//set the values for each of the properties
return cust;
}
Right now it is returning the whole class and I can use it like this:
lblDisplay = GetData("QUERY").CustAddr.ToString();
However, suppose each property takes a lot of time to compute. If I only want the CustAddr value, it still computes and has CustAcct
and CustInvoice
available for me.
How do I alter my function to only return the property I'm looking for, aside from breaking up my class into individual procedures to call? For example, I could just:
lblDisplay = GetCustAddr().ToString();
but that's not what I'm looking for. I think it's better to have all my data in an organized structure instead of a bunch of different procedures.