开发者

List<element> initialization fires "Process is terminated due to StackOverflowException"

开发者 https://www.devze.com 2022-12-24 05:30 出处:网络
I have structs like below and when I do that initialization: ArrayList nodesMatrix = null; List<vertex> vertexMatrix = null;

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<verte开发者_如何学运维x> 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; }


Your property setter is recursive.

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

Change this to be:

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

精彩评论

暂无评论...
验证码 换一张
取 消