There are several online tools you can use to tinker with C# without having to download software to your own computer. This can be a great starting point, but if you want to do meaningful things in C#, you will eventually want to download the SDK and an IDE or editor of some sort, so you can take advantage of everything C# has to offer. On the other hand, there are probably only a couple of challenges in the book (the ones relating to multiple files and project configuration) that cannot be done in an online editor, so choose the path that makes sense for you.
The first tool is try.dot.net. This is a good starting point that is intended for exactly the scenario we’re interested in here.
The big limitation is that it does not allow you to take advantage of a key new C# 9 feature: top-level statements.
The C# Player’s Guide uses top-level statements as the primary way to write C# programs.
Since you can’t take advantage of that here, you will have to adapt.
The starting code with the
public class Program and
public static void Main() will need to stay.
You’ll put your own code inside of the
Main() method, including new methods you write once you reach the level called Methods.
Also note that input (
Console.ReadLine, for example) is awkward.
You’ve got to type in your text in the popup and press “OK”, and then press “Cancel” without entering more text.
If you enter more text, then the second time you call
Console.ReadLine, it will use this text without prompting you for more.
It’s a little awkward, but not too hard to get used to.
A second tool that you can use is dotnet.microsoft.com/platform/try-dotnet.
The main advantage of this version is that you don’t have to deal with the
public class Program and
public static void Main().
There are two limitations:
- You do not have control over
usingdirectives. There is a set provided, and you can’t change it, though it contains most of the things used in the book.
- The editor is only a tiny slice of the whole window. You have less space to work in.
This also has the same approach for dealing with input (like
Console.ReadLine) as described in the previous section.
It’s awkward, but functional.
Another tool is dotnetfiddle.net.
If you use this, you will want to make sure you change the compiler in the drop-down on the right to .NET 5.
Input such as
Console.ReadLine does not seem to work well here, so you might need to get creative and modify the samples and your program.
I have also encountered some occurrences of this site basically telling me it cannot currently run code. That doesn’t happen all the time. It might even be extremely rare, and I’ve just been unlucky.
I hesitate to include this one in the list because you can’t actually run code in it. But this is Visual Studio Code online. It does not require a download, and allows you to edit your code, but does not allow you to run it unless you run it in a codespace, which is something you’d purchase via GitHub.
I generally would recommend the downloaded VS Code over this, but I could imagine this evolving to support running certain types of simple programs, such as console applications, online.
SharpLab.io is another editor that does not (currently) have the capacity to run your code. However, it can be quite useful for a number of other things. For example, you can use it to view the CIL instructions the C# compiler produces, as well as the machine instructions the JIT compiler turns it into, which gives you deep insight into how code is compiled without a lot of effort.
This is a good tool to augment a broader toolset, rather than an all-powerful unified tool.
There really are a lot of these out there. So doing a simple web search might find you a tool that you like better than the above. If you find one that you think is competitive or better than these others, I wouldn’t mind hearing about it so that I can update this page for others.