我有2个类Record和Pos。类Record有一个List。
public class Record
{
public string RecordNr { get; set; }
public List<Pos> Positions { get; set; }
public bool barred { get; set; }
public Vorgang()
{
RecordNr = "";
Positions = null;
barred = false;
}
}
public class Pos
{
public string PosNr { get; set; }
public string ArtNr { get; set; }
public Pos()
{
PosNr = "";
ArtNr = "";
}
}
如何在Record类中向List添加项目。
Pos cPos = new Pos
{
ArtNr = "35454",
PosNr = "1",
};
Record cRec = new Record ();
cRec.Positions.Add(cPos);
为什么我会收到System.NullReferenceException?