我想创建一个包含我正在处理的所有图钉对象的数组。当试图填充数组时,我得到一个NullReferenceException抛出的未处理错误。我已经阅读了尽可能多的文档,并且无法弄清楚发生了什么。NullReferenceException与C中的数组#
我已经试过至少有以下:
Pushpin[] arrayPushpins;
int i = 0;
foreach (Result result in arrayResults)
{
Pushpin pin;
pin = new Pushpin();
pin.Location = d;
myMap.Children.Add(pin);
arrayPushpins[i] = new Pushpin();
arrayPushpins.SetValue(pin, i);;
i++;
}
AND ...
Pushpin[] arrayPushpins;
int i = 0;
foreach (Result result in arrayResults)
{
Pushpin pin;
pin = new Pushpin();
pin.Location = d;
myMap.Children.Add(pin);
arrayPushpins[i] = new Pushpin();
arrayPushpins[i] = pin;
i++;
}
而且似乎没有任何工作。我每次都遇到了NullReference错误。 任何想法? 非常感谢! 请问。
为什么不使用IEnumerable集合呢? –
刚刚添加了这个,谢谢:-) –
初始化固定的数组。奇怪的是,我以为我也尝试过,但可能不会与使用SetValue方法结合使用。谢谢,阿米泰。我也会尝试使用一个Collection,因为我认为你是对的 - 在这种情况下会更好,因为引脚数量可能会有所不同。 –