I've written a lot of Python (and a bit of C/C++ many years ago) but am now staring on C# (.NET).
I'm using VSCode as my IDE.
I have the following folder structure
test/
├─ Program.cs
├─ Car.cs
with
//Program.cs
class Progam
{
static void Main(string[] args)
{
Console.Write("Hello SO!");
}
}
and that runs fine when I press CTRL+F5
(Run without debugging).
I've then moved into classes in C#, which is the Car.cs
file.
I have an error (I forgot a semicolon)
//Car.cs
class Car
{
string color = "red";
int n_wheels = 4 // Wups, missing semicolon
}
Note, I haven't changed the Program.cs
file, but now when I press CTRL+F5
I get the error
C:\Users\Me\Documents\C#\test\Car.cs(8,21): error CS1002: ; expected [C:\Users\Me\Documents\C#\test\Test.csproj]
I might still quite have understood how .NET/C# compiles the stuff and runs the program, but I just wonder, why it throws an error in the Car.cs
when that class isn't used at all in the Program.cs
, which is the only file that contains a Main
function.
I could understand if I've imported the Car
file but I do not - I don't use it anywhere and it does not have a Main
function.
So my question is; how do I avoid such stuff, when I have files that I'm currently developing (but am not using) that might have some bugs/issues due to it being under construction?