我知道这导致错误,但我不明白为什么以及如何解决它。我正在寻找避免创建数百个变量的方法
将其替换为
initialStopCollection [n]的.BufferUAbsolute
答案 0 :(得分:0)
您的代码应更改为:
set
{
int itemIndex = 1;
if (initialStopCollection == null) initialStopCollection = new ...; // your initialStopCollection is null. Create new one
if (itemIndex >= initialStopCollection.Count) // Two few items, create new
{
for (int i = initialStopCollection.Count; i <= itemIndex; i++)
{
initialStopCollection.Add(new ...);
}
}
if (initialStopCollection[itemIndex] == null) initialStopCollection[itemIndex] = new ... ; // This item is not initialized, create new
initialStopCollection[itemIndex].BufferUAbsolute = value;
}