gpt4 book ai didi

c# - 在 VS2010 中声明 List 属性时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 20:35:39 25 4
gpt4 key购买 nike

嗨我创建了两个用户控件(线路和车站)并在线路用户控件中使用站,最后我以某些形式使用“线路”用户控件。

在设计时没有问题,但是当我想在窗体中添加“Line”用户控件时。在这种情况下,visual studio 停止工作然后关闭。

我评论了我的代码中的一些更改,发现问题出在有关排队站数的属性上。当我评论它时,一切都很好,但我需要这个属性。这是我的代码

[Serializable]
public class ActionPoint
{
public string CarInfo;
public string RightStationName;
public string RightStationInfo;
public string LeftStationName;
public string LeftStationInfo;

public ActionPoint()
{
}
}

并在我的属性(property)中使用此类。我使用此属性来定义线路中的站点。

public class Line : UserControl
{
public List<ActionPoint> Stations
{
get { return Stations; }
set { Stations = value; }
}
}

最佳答案

该代码是递归的(当您尝试获取或设置该属性时,它会永远持续下去——遵循代码...); IDE 可能试图在属性网格中显示它,或者为 designer.cs 编写代码 - 并且正在触发友好的堆栈溢出异常。

适当的实现将是:

private List<ActionPoint> stations = new List<ActionPoint>();
public List<ActionPoint> Stations { get { return stations; } }

关于c# - 在 VS2010 中声明 List<myClass> 属性时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com