M
M
M_Egor2020-11-08 17:16:59
C++ / C#
M_Egor, 2020-11-08 17:16:59

When running a console application in C #, it gives "Stack overflow." how to fix?

Here is the code, I can't find the error

The code


Worker.cs
using System;

namespace Projects
{
    class Worker
    {
        public string name;
        public int Age{

            get => Age;
            set
            {
                if(Age > value)
                {
                    Console.WriteLine("Error");
                }
                else
                {
                    Age = value;
                }
            }
        }
        public int ID {get;set;}
        public int Pay {get;set;}

        public Worker(){}
        public Worker(string name,int Age,int ID,int Pay){
            this.name = name;
            this.Age = Age;
            this.ID = ID;
            this.Pay = Pay;
        }
        public void About()
        {
            Console.WriteLine("{0},{1},{2},{3}",name,Age,ID,Pay);
        }
    }
    
}

Program.cs
using System;

namespace Projects
{
    class Program
    {
        static void Main(string[] args)
        {

            Worker Thomas = new Worker("Thomas",24,0467,30000);
            Thomas.About();

            Console.ReadLine();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-11-08
@M_Egor

You Ageinstall itself and there is a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question