小注:这个错误在操作集合类Collection、List时,均会出现,原因是:Test类的属性没有实例化,在添加数据之前给它实例化一下,具体代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestSet
{
public class Test
{
public Test()
{
//
}
private List
_TestChilds;
///
/// 子类 ///
public List
TestChilds { //以下代码为修正代码 get { if (_TestChilds == null) { _TestChilds = new List
(); } return _TestChilds; } set { _TestChilds = value; } } } }