考虑下面的简单类及其参数化构造函数
public class UnitOfSave
{
public Question ObjQDTO { get; set; }
public List<Qtype> ListQType { get; set; }
public string OrgCode { get; set; }
public bool IsSystemQuestion { get; set; }
public string Language { get; set; }
public bool IsDirty { get; set; }
public int NoOfvalues { get; set; }
public UnitOfSave(Question ObjQDTO, List<Qtype> ListQType, string OrgCode, bool IsSystemQuestion, string Language)
{
this.ObjQDTO = ObjQDTO;
this.ListQType = ListQType;
this.OrgCode = OrgCode;
this.IsSystemQuestion = IsSystemQuestion;
this.Language = Language;
this.IsDirty = false;
}
public UnitOfSave() { }
}
// Below line of code throws error (Object reference not set to instance of variable) whenever ListQType has count 0 !!
QuestionMasterAPI.UnitOfSave Quantum = new QuestionMasterAPI.UnitOfSave(objQDTO, listQType, a_sOrgCode, b_IsSystemQuestion, language);
// Even the below test line throws same error.
QuestionMasterAPI.UnitOfSave Quantum = new QuestionMasterAPI.UnitOfSave();
当ListQtype中有对象时,代码才有效。你能不能指出UnitOfSave类定义有什么问题。
这与List<Qtype>
List。