sub*_*ime 7 c# arrays double list
您好我的c#Arrays有问题.我需要一个数组来存储一些数据...我的代码是那样的
double[] ATmittelMin;
ATmittelMin[zaehlMittel] = Gradient(x, xATmax, y, yATmax);
Run Code Online (Sandbox Code Playgroud)
但编译器说:未定义var如何定义没有固定大小的双数组?非常感谢!
Bli*_*ixt 21
数组总是固定大小,必须像这样定义:
double[] items1 = new double[10];
// This means array is double[3] and cannot be changed without redefining it.
double[] items2 = {1.23, 4.56, 7.89};
Run Code Online (Sandbox Code Playgroud)
所述List<T>
类使用阵列中的背景,当它运行的空间重新定义它:
List<double> items = new List<double>();
items.Add(1.23);
items.Add(4.56);
items.Add(7.89);
// This will give you a double[3] array with the items of the list.
double[] itemsArray = items.ToArray();
Run Code Online (Sandbox Code Playgroud)
您可以像对待List<T>
数组一样迭代正常:
foreach (double item in items)
{
Console.WriteLine(item);
}
// Note that the property is 'Count' rather than 'Length'
for (int i = 0; i < items.Count; i++)
{
Console.WriteLine(items[i]);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
39225 次 |
最近记录: |