A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Hello World in C# page! Here, you’ll find the source code for this program as well as a description of how the program works.
namespace SamplePrograms
{
public class HelloWorld
{
static void Main()
{
System.Console.WriteLine("Hello, World!");
}
}
}
Hello World in C# was written by:
If you see anything you’d like to change or update, please consider contributing.
Note: The solution shown above is the current solution in the Sample Programs repository as of Jul 24 2018 10:04:46. The solution was first committed on Mar 21 2018 00:11:57. As a result, documentation below may be outdated.
Now, we can implement Hello World in C# in a couple of ways. For simplicity, I’ll share the minimalist approach but be aware that there are more complete ways to do this:
class HelloWorld {
static void Main() {
System.Console.WriteLine("Hello, World!");
}
}
If you read the Hello World in Java tutorial, then this probably looks very similar. In fact, C# shares a lot of the same look and feel as Java. With that being the case, I’ll only highlight the major pieces here.
Before we can print, we have to create a class. Inside our class, we declare the main method. And inside our main method, we run our print command. The syntax and core libraries are a little different, but it feels eerily similar to Java.
Perhaps the easiest way to run this solution would be to open up an online C# compiler. Just copy the code from above and drop it into the editor before hitting run.
Alternatively, we can download Visual Studio or Mono to run C# locally. Of course, we’ll want a copy of the solution as well. Refer to the manual of the various tools to run C#.
As far as I know, there aren’t any easy ways to run C# code from the command line, but I imagine it can be done.