我在VS2008中有一个用C#编写的类。这个类是递归的。
当我对这个类的实例进行调试并在调试时查看它时,VS2008会停止几秒钟然后调试会话退出。
任何想法可能是什么问题。
班级
public class TextSection
{
private bool used;
private string id;
private HL7V3_CD code;
private string title;
private string text;
public List<TextSection> section;
public TextSection()
{
used = false;
section = new List<TextSection>();
}
public bool Used
{
get { return used; }
}
public string Title
{
get { return title; }
set
{
used = true;
title = value;
}
}
public string Text
{
get { return text; }
set
{
used = true;
text = value;
}
}
public string Id
{
get { return id; }
set
{
used = true;
id = value;
}
}
public HL7V3_CD Code
{
get { return Code; }
set
{
used = true;
code = value;
}
}
}
在退出之前调试VS2008的屏幕截图时显示here
答案 0 :(得分:6)
问题是这个属性
public HL7V3_CD Code
{
get { return Code; }
set
{
used = true;
code = value;
}
}
当调试器试图从属性Code中获取值时,它将生成一个StackOverflowException,导致Code调用自身而不是返回变量的值
答案 1 :(得分:6)
您应该更改此细分
public HL7V3_CD Code
{
get { return Code; }
set
{
used = true;
code = value;
}
}
到
public HL7V3_CD Code
{
get { return code; }
set
{
used = true;
code = value;
}
}