对象引用未设置为变量的实例

时间:2016-03-08 10:42:56

标签: c# null nullreferenceexception

考虑下面的简单类及其参数化构造函数

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。

有关 编辑:当我调试时,我可以将F11转换为正确的构造函数,并且它完美地执行,当它返回到所述行时,然后抛出下一个F10命中的异常。这真的很有趣。

0 个答案:

没有答案
相关问题