❔ Only one compilation unit can have top-level statements. [C# start]
using VS code, just created new file apart from program.cs and got this error
17 Replies
then, dont use top level statements there, but normal classes
for example
if ur
Program.cs
looks like this for example:
its nothing different than that it automatically will be converted to
in the end. top level statements are to get rid of that boiler plate code
also for beginners i would recommend using Visual Studio, not Visual Studio Code if possibleim so confused, sorry Im so new to C#
my code doesnt have "using system:"
In every C# project, there is one file that will be run at the start of your program - Program.cs.
You cannot have multiple of these files, there can only be one.
ok
so what if i want to write a new code but want to keep my old one
You create a new project
how do u do that on vs code?
Same way you created your current project
dotnet new console
presumablyok
but when i did that it just runs my original project, not my new one
@thinker227 what should i do?
@cap5lut ???
Go into your new project in the terminal and run
dotnet run
what if i want to run it in terminal?
does that not work?
It does
in terminal on my mac as in externally?
whatever, ill just run in app
Well, any terminal will work
ok its fine i think I was running it wrong
can i ask u if I have any more questions as I am very new to C# and coding in generall and you seem like you know what your doing
You can always ask in #help or #help-0
ok
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.