0
尝试创建一个自定义对象,该对象将允许我在记录中拾取错误。将值分配给属性时出现空错误
public class gridIntegerField
{
private int value;
private bool isValid;
private string message;
public int Value
{
get { return this.value; }
set { this.value = value; }
}
public bool IsValid
{
get { return isValid; }
set { isValid = value; }
}
public string Message
{
get { return message; }
set { message = value; }
}
}
public class gridRecord
{
private gridIntegerField printRun;
public gridIntegerField PrintRun
{
get { return printRun; }
set { printRun = value; }
}
}
当创建对象,试图把我得到如下因素误差值...
型“System.NullReferenceException”未处理的异常发生在基于XML Console.exe
代码为创建对象...
gridRecord spr = new gridRecord();
spr.PrintRun.Value = 200;
spr.PrintRun.IsValid = true;
spr.PrintRun.Message = "No Errors";
Console.WriteLine(spr.PrintRun.Value.ToString());
Console.WriteLine(spr.PrintRun.IsValid.ToString());
Console.WriteLine(spr.PrintRun.Message.ToString());
Console.ReadKey();
错误发生在这行代码
spr.PrintRun.Value = 200;
spr.PrintRun = new gridIntegerField()add before assign value –