列表<元素>初始化引发“进程由于 StackOverflowException 而终止”元素>
我有如下结构,当我进行初始化时:
ArrayList nodesMatrix = null;
List<vertex> vertexMatrix = null;
List<bool> odwiedzone = null;
List<element> priorityQueue = null;
vertexMatrix = new List<vertex>(nodesNr + 1);
nodesMatrix = new ArrayList(nodesNr + 1);
odwiedzone = new List<bool>(nodesNr + 1);
priorityQueue = new List<element>();
arr.NodesMatrix = nodesMatrix;
arr.VertexMatrix = vertexMatrix;
arr.Odwiedzone = odwiedzone;
arr.PriorityQueue = priorityQueue; //only here i have exception
调试器触发进程由于 StackOverflowException 而终止:/ 知道为什么这个集合会引发这个异常吗?
private struct arrays
{
ArrayList nodesMatrix;
public ArrayList NodesMatrix
{
get { return nodesMatrix; }
set { nodesMatrix = value; }
}
List<vertex> vertexMatrix;
public List<vertex> VertexMatrix
{
get { return vertexMatrix; }
set { vertexMatrix = value; }
}
List<bool> odwiedzone;
public List<bool> Odwiedzone
{
get { return odwiedzone; }
set { odwiedzone = value; }
}
public List<element> PriorityQueue
{
get { return PriorityQueue; }
set { PriorityQueue = value; }
}
}
public struct element : IComparable
{
public double priority
{
get { return priority; }
set { priority = value; }
}
public int node
{
get { return node; }
set { node = value; }
}
public element(double _prio, int _node)
{
priority = _prio;
node = _node;
}
#region IComparable Members
public int CompareTo(object obj)
{
element elem = (element)obj;
return priority.CompareTo(elem.priority);
}
#endregion
I have structs like below and when I do that initialization:
ArrayList nodesMatrix = null;
List<vertex> vertexMatrix = null;
List<bool> odwiedzone = null;
List<element> priorityQueue = null;
vertexMatrix = new List<vertex>(nodesNr + 1);
nodesMatrix = new ArrayList(nodesNr + 1);
odwiedzone = new List<bool>(nodesNr + 1);
priorityQueue = new List<element>();
arr.NodesMatrix = nodesMatrix;
arr.VertexMatrix = vertexMatrix;
arr.Odwiedzone = odwiedzone;
arr.PriorityQueue = priorityQueue; //only here i have exception
debuger fires Process is terminated due to StackOverflowException :/
Some idea why this collection fires this exception ?
private struct arrays
{
ArrayList nodesMatrix;
public ArrayList NodesMatrix
{
get { return nodesMatrix; }
set { nodesMatrix = value; }
}
List<vertex> vertexMatrix;
public List<vertex> VertexMatrix
{
get { return vertexMatrix; }
set { vertexMatrix = value; }
}
List<bool> odwiedzone;
public List<bool> Odwiedzone
{
get { return odwiedzone; }
set { odwiedzone = value; }
}
public List<element> PriorityQueue
{
get { return PriorityQueue; }
set { PriorityQueue = value; }
}
}
public struct element : IComparable
{
public double priority
{
get { return priority; }
set { priority = value; }
}
public int node
{
get { return node; }
set { node = value; }
}
public element(double _prio, int _node)
{
priority = _prio;
node = _node;
}
#region IComparable Members
public int CompareTo(object obj)
{
element elem = (element)obj;
return priority.CompareTo(elem.priority);
}
#endregion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
PriorityQueue
属性正在引用自身。您需要更改访问器才能使用字段。
但是,您应该使用自动实现的属性:
Your
PriorityQueue
property is referencing itself.You need to change the accessors to use a field.
However, you should use automatically-implemented properties instead:
您的属性设置器是递归的。
将其更改为:
Your property setter is recursive.
Change this to be: