I can't even run my code.
Hi! I'm trying to start learning C# in visual studio community but my visual studio just doesn't look the same as the people in youtube tutorials. I can't even press F5 to run a simple Hello World... Any idea on what might be the problem?
46 Replies
It looks like you don't have any projects added to your solution. Did you perhaps open a
.cs
file directly inside VS instead of opening the .csproj
?
C# is project based, so you must open a project fileit says Program.cs in the top left
should it say .csproj instead there?
No, I just think you opened the wrong file when you started Visual Studio
as said, C# is project based
its not like python or JS where you can run an individual file
When I launch vscommunity i press the create a new project
then chose Console App
Okay, seems good
i use net 6.0, it's the standard option
No reason not to use 7.0, but thats a minor issue
and when it opens
i get this:
hm okay
thats not how its supposed to look
if you look top right, you see it says "0 projects"
yeah
okay lets try doing it via the terminal
open up a command prompt or terminal and navigate to where you want the code to be
how do I do that?
WIN+R and type "cmd"
oooh
aight, then?
well, where do you want the code to be on your computer?
Im guessing your prompt says something like
C:\Users\<yourusername>
don't i write the code in visual studio community
yeah it does
Are you aware of how the computer stores files on your harddrives?
your code is files. on your harddrives.
ooh yeah
I keep all my code in
D:\Code
, but if you dont have a second drive you can just put it on Cyeah i just have an ssd so it all gets stored on my ssd
C drive
okay great
so lets do
cd ..
twice
then mkdir code
then cd code
done
and your prompt says
C:\code
now?yes
great
then do
dotnet new console -n MyTestProject
oooh
you dont have any SDKs installed
lets verify
do
dotnet --info
and show me what it saystwo dashes
Ah, you have installed an x86 version
lets swap to the x64
how do i do that?
are you able to screenshare?
yeah :)
its a bit tricky to explain over text
#dev-vc-1
$helloworld
Written interactive course https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
Videos https://dotnet.microsoft.com/learn/videos
👻
Tja. Behöver jag ha med "private static void" grejen och internal class program i min kod?
för det är något error med internal class Program står det
English only in written channels.
You seem to have two
Program
classes in the same namespace
thats not allowed
and the declaring of a class and main method CAN be skipped, but I recommend against it as a beginner
since thats unique to just the main method, everwhere else you still need to make classesHi! I got help from some people in vc with the program issue and it's fixed now.
I'll look up a tutorial on how to declare it :)