将数据存储在for循环中

时间:2019-06-26 20:44:13

标签: c#

我有一个for循环,我想做的是将每个for循环的数据存储在C#中。 目前,它仅存储上一次迭代的数据。

附上我的代码。非常感谢!

for (int i = 0; i < n; i++)
{
    if (i <= k - p - 1)
    {
        alpha[i] = 1;
        NewCPVector[i] = CPVector[i];
    }
    if (k - p <= i && i <= k-1)
    {
        alpha[i] = (FinalKnotsVector[k] - Initialknots[i]) / (Initialknots[i + p + 1] - Initialknots[i]);
        NewCPVector[i] = alpha[i] * CPVector[i] + (1 - alpha[i]) * CPVector[i - 1];
    }
    if (i >= k)
    {
        alpha[i] = 0;
        NewCPVector[i] = CPVector[i - 1];
    }
}

1 个答案:

答案 0 :(得分:0)

我将假设您的数组包含双精度值。 (但是可能是其他类型,例如float或小数),您只需在列表的声明中指定该类型 您可以通过以下方式将数据保存在列表中:

dependencies {
    //...
    implementation 'android.arch.lifecycle:extensions:1.1.1'
}