我正在尝试调试由我创建的类的对象组成的列表中的一些信息。当我尝试检查它时,它将停止调试,并在输出窗口中给出以下代码:
程序<6880> 'MyApp.vshost.exe‘已经退出,代码为-2147023895 (0x800703e9)。
当我搜索这个号码时,我发现了这个:
递归太深;堆栈溢出。
当我读到这篇文章时,我觉得我有一个无限的循环或者类似的东西。
当我搜索这个,我到MSDN,它说联系供应商。那就是我..。
我在堆栈溢出中发现的另一个主题是:Runtime exception, recursion too deep
但这是关于循环的。很长一段时间。
我的只是一个列表,里面保存了一些信息。
这是一堂课
class LinePiece
{
private string type;
private string elementNumber;
private int beginX, beginY;
private int endX, endY;
private int diameter;
private string text;
public string Type { get { return type; } }
public string ElementNumber { get { return ElementNumber; } }
public int BeginX { get { return beginX; } }
public int BeginY { get { return beginY; } }
public int EndX { get { return endX; } }
public int EndY { get { return endY; } }
public LinePiece(string a_type, string a_eleNr, int a_beginX, int a_beginY, int a_endX, int a_endY)
{
type = a_type;
elementNumber = a_eleNr;
beginX = a_beginX;
beginY = a_beginY;
endX = a_endX;
endY = a_endY;
}
}我创建了这样一个列表:List<LinePiece> l_linePieces = new List<LinePiece>();
再加上这样的一行:
LinePiece LP = new LinePiece(s_lpType, s_EleNr, i_X1, i_Y1, i_X2, i_Y2);
l_linePieces.Add(LP);此时调试时,我单击l_linePieces,它将显示其中包含的对象数量。但是当我试图打开其中一个时,它会停止并给出错误。
另外,当我不调试它的时候,一切都很好,没有错误等等。但是我想检查一下这个列表中的一些值。
那么我该如何解决这个问题呢?
发布于 2017-01-19 14:38:41
这个财产..。
public string ElementNumber { get { return ElementNumber; } }...calls本身。
为了避免将来发生这种情况,您可能应该使用自动属性,如下所示:
public string ElementNumber { get; set; }编译器将发明一个隐藏的备份字段。
您可以在构造函数中初始化自动属性,如下所示:
public LinePiece(string a_type, string a_eleNr,
int a_beginX, int a_beginY,
int a_endX, int a_endY)
{
Type = a_type;
ElementNumber = a_eleNr;
BeginX = a_beginX;
BeginY = a_beginY;
EndX = a_endX;
EndY = a_endY;
}如果只想从类本身(即构造函数中)设置它们,则使用private set
public string ElementNumber { get; private set; }https://stackoverflow.com/questions/41744409
复制相似问题