Learning C#, But First…
To better prepare myself for a job interview, I recently decided to try C#. Having already learned some C and a little C++, I figured it wouldn’t be too difficult. When learning a new language, I like to start with something like Codecademy, which gived basic instructions in a built in IDE, and then follow up each lesson trying to replicate it myself in Visual Studio Code in my local environment. This way, I can learn syntax in a structured way, but also learn about how to create actual files and practice using git.
C# was going pretty well in Codecademy, and I felt comfortable trying to get it working in my local environment. This was where the trouble began. I am running vscode on a Windows 10 machine, but due to the requirements of Flatiron School I do so using Ubuntu and the Windows Subsystem for Linux (WSL) as my terminal. While I am on a PC, as far as vscode and my command line are concerned, I am on Linux. C# was the first language I’ve used where there is more to installing the language than downloading an extension for vscode, and more to a program than a file with legible code.
Because Codecademy’s IDE is in browser and meant to be user friendly, files are already in place for each activity, and running a file is as easy as running dotnet run
in the command line. trying to do it locally, I wrote my helloWorld.cs
file, ran dotnet run
, and was confronted with more errors than I had seen before. Apparently, having the C# extension for vscode isn’t enough, I need to install the language on my computer! Okay, the error message contains a helpful link to the microsoft page with the download link, so off I go, download the .Net Code SDK, and try again.
dotnet: command not found
. This error would become the bane of my existence. Several forum posts tell me the problem is that dotnet is not correctly added to my computer’s path
, along with helpful instructions on how to add it. Off I go to the control panel -> system and security -> system -> advanced system settings -> advanced -> environment variables -> system variables -> path … and dotnet is already there, along with the correct file address.
Running dotnet --version
from the windows command line reveals that I do, in fact, have .Net installed correctly. According to the official troubleshooting page for my error, there is no reason it shouldn’t work.
But then I remember that as far as my vscode terminal is concerned, I am on Linux, rather than windows. I check the path
in my WSL terminal with echo "$PATH"
, and lo and behold dotnet is nowhere to be seen. I go back to the .Net download page, and go through the process of installing it on linux, using my Ubuntu terminal. I run dotnet --version
in Ubuntu, and still no luck. Check the path
again, and it is there. Half success!
It is at this point that I make my crucial observation. In Windows, the path
needs to contain the address for dotnet.exe
. In Linux and MacOs, it only contains dotnet
. What if I tried dotnet.exe --version
?
5.0.202
. Finally, it works. Because of system shenanigans, WSL would not recognize dotnet
as a command, but it would recognize dotnet.exe
. Glowing fresh with victory, I return to my helloWorld
folder, run dotnet.exe run
, and immediately get an error that there are no projects in the location. When I made the file, I didn’t use dotnet.exe new console
, which is necessary to create the files that tells the computer the folder contains a C# project. So that still doesn’t work, but at least now I know why, and I know what to do the NEXT time I want to create a C# program. This is why I don’t rely on things like Codecademy with build in IDE’s. They are great for learning the syntax of a new language, but the minutia of actually creating folders and files are lost, and that minutia is what allows you to actually build real applications. Why else are we learning a programming language?