数组,Arraylist或列表列表?

Sta*_*age 2 .net c# .net-4.0 c#-4.0

我打算使用标准数组,我需要x行数和2列

double[,] members = new double[x, 2];
Run Code Online (Sandbox Code Playgroud)

并循环遍历我得到的所有结果,然后将它们添加到数组中,但由于结果数量可以更改,我不想预先定义数组的大小...

members[0, 0] = cost;
members[x, 1] = tax;
x++;
Run Code Online (Sandbox Code Playgroud)

我正在考虑调整数组大小,但是为此更简单地使用arraylist或列表列表会更容易吗?

Mar*_*ell 7

我会有一个类型的列表,其中该类型有成本和税.

如果空间是溢价,它可能是一个带有两个双精度的结构(顺便说一下,十进制会更合适吗?它几乎总是更好的选择),但如果是这样的话:让它变成不可变的.

例如:

public struct YourType {
    private readonly decimal cost, tax;
    public decimal Cost { get { return cost; } }
    public decimal Tax { get { return tax; } }
    public YourType(decimal cost, decimal tax) {
        this.cost = cost;
        this.tax = tax;
    }
}
Run Code Online (Sandbox Code Playgroud)

附:

List<YourType> list = new List<YourType>();
Run Code Online (Sandbox Code Playgroud)