公共属性的设置器将“值”分配给集合时出现序列化错误

本文关键字:集合 分配 错误 序列化 属性 设置 | 更新日期: 2023-09-27 18:36:59

我知道这导致了错误,但我不明白为什么以及如何解决它。我正在寻找一种避免创建数百个变量的方法

  • is1_BufferUAbsolute
  • is2_BufferUAbsolute
  • is75_BufferUAbsolute

通过将其替换为

initialStopCollection[n].BufferUAbsolute

序列化错误

公共属性的设置器将“值”分配给集合时出现序列化错误

您的代码应更改为:

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