我正在尝试调试我的列表中的一些信息,这些信息是由我制作的类的对象组成的.当我尝试检查它时,它会停止调试并在输出窗口中提供以下代码:
程序<6880>'MyApp.vshost.exe'已退出,代码为-2147023895(0x800703e9).
当我搜索这个号码时,我发现了这个:
递归太深; 堆栈溢出.
当我读到这篇文章时,在我看来,我有一个无限循环或类似的东西.
当我搜索这个时,我会访问MSDN并说它与供应商联系.那就是我......
我在stackoverflow上发现的另一个话题是:运行时异常,递归太深
但这是关于像...很长时间的循环.
我只是一个列表,其中保存了一些信息.
这是班级
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个这样的列表: 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);
Run Code Online (Sandbox Code Playgroud)
当我在此时进行调试时,我点击l_linePieces
它会显示其中的对象数量.但是当我尝试打开其中一个时,它会停止并给出错误.
此外,当我不调试它,它没关系,它没有错误等.但我想检查此列表中的一些值.
那么我该如何解决这个问题呢?
这个属性getter ...
public string ElementNumber { get { return ElementNumber; } }
Run Code Online (Sandbox Code Playgroud)
......自称.
为了避免将来出现这种情况,您应该使用自动属性,如下所示:
public string ElementNumber { get; set; }
Run Code Online (Sandbox Code Playgroud)
编译器将发明一个隐藏的支持字段.
您可以在构造函数中初始化自动属性,如下所示:
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;
}
Run Code Online (Sandbox Code Playgroud)
如果你只想从类本身(即在构造函数中)设置它们,那么使用private set
:
public string ElementNumber { get; private set; }
Run Code Online (Sandbox Code Playgroud)