Suppose I have a simple class that Adds:
public class Multiply
{
public int A {get; set;}
public int B {get; set;}
public int C {get; set;}
public List<int> Result {get; set;}
public void Calculate()
{
if (A != 0 && B!= 0 && C != 0)
{
Result.Add(A);
Result.Add(B);
Result.Add(C);
Result.Add(A * B);
Result.Add(A * C);
Result.Add(B * C);
Result.Add(A * B * C);
}
}
}
The above class models my actual application. I have a series of parameters that get set, in this case A, B and C. I then execute Calculate and use the Multiply object's Result property to access the result.
(There might be a better ways to accomplish this template; Lazy loading comes to mind. If you want to suggest a better template go for it but its not the purpose of my question; its just a simple example that illustrates my question.)
Here is my question:
If I'm using the Object Intializer Syntax:
Multiply m = new Multiplier()
{
A = 1,
B = 2,
C = 3
}
m.Calculate();
DoSomething(m.Result[5]); //DoSomething(6);
Is there a way to execute Calculate() as part of the m initialization?