EDIT: It turns out that the local variable was not the issue. Even after changing it I get the error message from Visual Studio Community (was using VS code before):
"An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
If I create a new project, and copy and paste the code, a different message appears:
The debug executable 'D:\Desktop\New folder\ConsoleApp1\ConsoleApp1\bin\Debug\netcoreapp3.1\ConsoleApp1.exe' specified in the 'ConsoleApp1' debug profile does not exist
A problem also appears saying the program does not contain a Static Main, but the previous replies say the code works as it is.
OLD:
At college we have done a C# exercise (code will be further down) that for some reason does not work on my computer, despite being exactly the same (I have even copy and pasted someone else's that did work on theirs but not on mine). The code was meant to accept a number from the user and see if it was within a range or not, and depending on that output a message.
For some reason, it appears that a local variable is not being read as it shows up as the wrong color, but if you hover the mouse over the word, a pop-up menu does say it is a local variable. The variable is the 'result' after the 'if' and before the brackets (line 15).
At first we thought it was a problem with Visual Studio Code, so I tried it on Visual Studio Community 2019 and it still did not work. I already have the relevant framework. My teachers think there is a problem with my device, what do you think?
Here is how it looks in VS code
Here is the pop-up menu that appears
Here are the list of problems after debugging
And here is the source code:
using System;
namespace Csharp_learning
{
class MainDemo
{
static int ReadNumber(string prompt, int min, int max)
{
int result = 0;
do
{
Console.Write(prompt);
string numberString = Console.ReadLine();
result = int.Parse(numberString);
if result (result > max || result < min)
Console.WriteLine("Please enter a value in the range " + min + " to " + max);
else
break;
}
while(true);
return result;
}
}
}
This is my first time using this website, sorry if I did not present this correctly.