清单<组件>初始化火灾"处理被终止由于StackOverflowException" [英] List<element> initialization fires "Process is terminated due to StackOverflowException"

查看:201
本文介绍了清单<组件>初始化火灾"处理被终止由于StackOverflowException"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像下面结构,当我这样做初始化:

  ArrayList的nodesMatrix = NULL; 
名单,LT;顶点> vertexMatrix = NULL;
名单,LT;布尔> odwiedzone = NULL;
名单,LT;组件> PriorityQueue中= NULL;

vertexMatrix =新的List<&顶点GT;(nodesNr + 1);
nodesMatrix =新的ArrayList(nodesNr + 1);
odwiedzone =新的List<布尔>(nodesNr + 1);
的PriorityQueue =新的List<组件>();

arr.NodesMatrix = nodesMatrix;
arr.VertexMatrix = vertexMatrix;
arr.Odwiedzone = odwiedzone;
arr.PriorityQueue = PriorityQueue的; //只有在这里,我有例外



debuger火灾的进程被终止由于StackOverflowException :/
的一些想法,为什么这个集合大火此异常

 私人结构数组
{$ b? $ b的ArrayList nodesMatrix;

公众的ArrayList NodesMatrix
{
{返回nodesMatrix; }
集合{nodesMatrix =价值; }
}
名单,LT;顶点> vertexMatrix;

公开名单<&顶点GT; VertexMatrix
{
{返回vertexMatrix; }
集合{vertexMatrix =价值; }
}
名单,LT;布尔> odwiedzone;

公开名单<布尔> Odwiedzone
{
{返回odwiedzone; }
集合{odwiedzone =价值; }
}
公开名单<组件> PriorityQueue中
{
{返回的PriorityQueue; }
集合{PriorityQueue的=价值; }
}


}
公共结构元素:IComparable的
{
公共双优先
{
获得{返回优先; }
集合{优先=价值; }
}
公众诠释节点
{
{返回节点; }
集合{节点=值; }
}
公共元素(双_prio,诠释_node)
{
=优先_prio;
节点= _node;
}

#地区IComparable的会员

公众诠释的CompareTo(obj对象)
{
元素ELEM =(元)目标文件;
返回priority.CompareTo(elem.priority);
}

#endregion


解决方案

的PriorityQueue b,您需要更改访问使用字段属性引用本身。结果$ b $。

 列表<组件> PriorityQueue中; 
公开名单<组件> PriorityQueue中
{
{返回的PriorityQueue; }
集合{PriorityQueue的=价值; }
}



不过,你应该使用自动实现的属性,而不是:



 公开名单<组件> PriorityQueue中获得{;组; } 


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

解决方案

Your PriorityQueue property is referencing itself.
You need to change the accessors to use a field.

List<element> priorityQueue;
public List<element> PriorityQueue
{
    get { return priorityQueue; }
    set { priorityQueue = value; }
}

However, you should use automatically-implemented properties instead:

public List<element> PriorityQueue { get; set; }

这篇关于清单&LT;组件&gt;初始化火灾&QUOT;处理被终止由于StackOverflowException&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆