I dont understand the problem? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I dont understand the problem?

Hello, I'm a beginner in C# and i wrote this code, but unfortunately, every time I start it it says StackOverflow. So how can I fix the problem??? and here words translated to English (from German) so that everyone understands it: Tier: animal anzahlBeine: numberOfLegs weichheitDesFells: fluffinesOfThePelt alter: age Affe: ape :::::: this is a code I wrote to understand things better and has no use whatsoever :::::: namespace Teste_Test { public class Tier { public int anzahlBeine { get; set; } public string name { get; set; } public int weichheitDesFells { get { return anzahlBeine; } set { weichheitDesFells = value; } } public double alter { get { return alter; } set { alter = value; } } public Tier(int anzahlBeine, int weichheitDesFells, string name, double alter) { this.anzahlBeine = anzahlBeine; this.weichheitDesFells = weichheitDesFells; this.name = name; this.alter = alter; Console.WriteLine("hello"); } } public class Affe : Tier { public Affe(int anzahlBeine, int weichheitDesFells, string name, double alter) : base (anzahlBeine, weichheitDesFells, name, alter) { } } class Program { static void Main(string[] args) { Affe ulu = new Affe(anzahlBeine: 2, weichheitDesFells: 3, name: "ulu", alter: 13); ulu.anzahlBeine = 2; ulu.weichheitDesFells = 2; Console.WriteLine(ulu.weichheitDesFells); } } }

18th Feb 2020, 2:34 PM
Michael
5 Answers
+ 3
Hey bro, you are referring to the property to return itself, this causes an infinite loop of trying to access its own value. Hence, StackOverFlow. I changed your code. https://code.sololearn.com/c2PsNmS2P5YR/?ref=app
20th Feb 2020, 8:11 PM
hossein B
hossein B - avatar
+ 2
Hi,. could you please C&P that code into playground and link it here?
18th Feb 2020, 2:53 PM
Oma Falk
Oma Falk - avatar
18th Feb 2020, 3:14 PM
Michael
0
and when i write it in Visual Studio it isnt underlining anything red
18th Feb 2020, 3:16 PM
Michael
0
thank you all I think i understood what my mistake was
21st Feb 2020, 5:35 PM
Michael