C# 类型为';的未处理异常;System.StackOverflowException';发生在application.exe中
application.exe中发生“System.StackOverflowException”类型的未处理异常我不知道为什么会发生这种情况您的值获取程序中有一个无休止的递归调用:C# 类型为';的未处理异常;System.StackOverflowException';发生在application.exe中,c#,C#,application.exe中发生“System.StackOverflowException”类型的未处理异常我不知道为什么会发生这种情况您的值获取程序中有一个无休止的递归调用: public object Value { get { if (this.realDate) return (object)base.Value; return (object)DBNull.Value; } set {
public object Value
{
get
{
if (this.realDate)
return (object)base.Value;
return (object)DBNull.Value;
}
set
{
if (Convert.IsDBNull(value))
{
this.realDate = false;
this.oldFormat = this.Format;
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = " ";
}
else
{
this.realDate = true;
// the line below is erroneous
this.Value = Convert.ToDateTime(value);
}
}
}
这会导致堆栈溢出
(object)base.Value;
这将再次调用值的setter。因此,您正在从setter从setter从setter调用setter…导致无限循环,该循环被StackOverflowException停止
您应该有一个将值写入的支持字段,例如:
public object Value
{
…
set
{
this.Value = value;
}
}
返回(object)base.Value的是什么代码>做什么?我猜它又在调用同一个访问器。不过我们不能不说。而且你的setter肯定在为非空值调用自己…@saqibali不客气!请记住,如果解决了您的问题,请将此问题标记为已解决。
private object _value;
public object Value
{
get { return _value; }
set
{
// some logic
_value = value;
}
}