Can not evaluate expression because the current thread is in stack overflow state

3

You're giving this error:

  

Can not evaluate expression because the current thread is in stack overflow state

in the qtde variable by adding it in the desci list.

class descricaoo : IInstrucao
    {
        private string descricaobol;
        public descricaoo(int ibanco, int codigo, string descricaobol, int qtde)
        {
            this.descricaobol = descricaobol;
            List<IInstrucao> desci = new List<IInstrucao>();
            desci.Add(new descricaoo(ibanco, codigo, descricaobol, qtde));
        }
        public IBanco Banco { get; set; }
        public int Codigo { get; set; }
        public string Descricao { get; set; }
        public int QuantidadeDias { get; set; }
    }
    
asked by anonymous 29.10.2015 / 17:43

1 answer

3

Pay attention to what you are doing. It enters the descricaoo constructor, inside it you create a list and add an item to it. This item is created by calling a new object of the same class. That is, it will call this constructor again. What happens to him? He'll call this builder one more time. And so it goes indefinitely. Until the memory reserved to allocate local variables has no more space and pops up.

Your logic is very wrong. Rethink the problem and see how you have to create this class. I can not help much without knowing the problem, but you can see that there are several problems, not only in the constructor, but in the whole class. Maybe in the whole application.

    
29.10.2015 / 17:49