2D配列を使用できます。
int numSums = 4;
int[,] sums = new int[numSums,3];
// 1 + 1 = 2
sums[0,0] = 1;
sums[0,1] = 1;
sums[0,2] = sums[0,0] + sums[0,1];
// 5 + 5 = 10
sums[1,0] = 5;
sums[1,1] = 5;
sums[1,2] = sums[1,0] + sums[1,1];
// 3 + 2 = 5
sums[2,0] = 3;
sums[2,1] = 2;
sums[2,2] = sums[2,0] + sums[2,1];
// 2 + 2 = 4
sums[3,0] = 2;
sums[3,1] = 2;
sums[3,2] = sums[3,0] + sums[3,1];
クラスを使用して、最もクリーンな効果を実現することもできます。
private List<Equation> sums = new List<Equation>();
public MyConstructor() {
sums.Add(new Equation(5, 5));
Console.WriteLine (sums[0].a + " + " + sums[0].b + " = " + sums[0].sum);
}
private class Equation {
public int a;
public int b;
public int sum {
get { return a + b; }
}
public Equation(int a, int b) {
this.a = a;
this.b = b;
}
}