C
C#15mo ago
Faste

✅ Why this insta close program

So when i add if (nrM <= 0) with back(); my program close instantly after start. Let me know why first in order console.readline() not work even if later in program is hidden problem, till i not type value should work. And other question can i use back(); like i want here to start from begining its my favourite method so if possible i want this way Sorry i ask simple question like this i know i can easy find how to fix but i want understand why this not work static void Main(string[] args) { void back() { short maxValue = short.MaxValue; Console.WriteLine("Type nr from 1 to " + maxValue); short nrM = short.Parse(Console.ReadLine()); if (nrM > maxValue) { Console.WriteLine("You type too big nr we set it to max possible value: " + maxValue); nrM = maxValue; }if (nrM <= 0) { Console.WriteLine("You type nr smaller than 1, Choose again."); back(); } for (short i = nrM; i > 0; i--) { Console.WriteLine(i); } Console.ReadLine(); } }
4 Replies
Omnissiah
Omnissiah15mo ago
i guess you have a stack overflow? you can chek the crash in event viewer or just debug it...
Faste
FasteOP15mo ago
i just start programming in C# 2 hours ago i use visual studio 2022 ahh stack overflow is website nvm
Anu6is
Anu6is15mo ago
Two things 1. As a beginner you should learn how to use the debugger. Stepping through your code helps you see exactly what's going on https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour 2. You can't use back() like that.... take it out of main and call it from main
Faste
FasteOP15mo ago
Thanks
Want results from more Discord servers?
Add your server