定义无固定大小双数组? [英] Define a double array without a fixed size?

查看:105
本文介绍了定义无固定大小双数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有C#数组的一个问题。我需要一个数组来的一些数据存储在那里...
我的code是

Hello i have a problem with c# Arrays. I need a array to store some data in there... My Code is that

double[] ATmittelMin;
ATmittelMin[zaehlMittel] = Gradient(x, xATmax, y, yATmax);

但是,编译器说:没有定义VAR
我如何定义没有一个固定大小的双数组?
非常感谢!

But the compiler says: not defined var How can i define a double array without a fixed size ? Thanks a lot!

推荐答案

数组总是固定的大小,并已到,像这样定义:

Arrays are always fixed in size, and have to be defined like so:

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};

列表< T> 类使用数组在后台,当它运行的空间,重新定义它:

The List<T> class uses an array in the background and redefines it when it runs out of space:

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();

您可以通过迭代一个列表&LT; T&GT; 就像你将一个数组:

You can iterate through a List<T> just as you would an array:

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]);
}

这篇关于定义无固定大小双数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆