Exercise – Write your first code
In this first hands-on exercise, you’ll use C# to print a hallowed programmer’s phrase to the standard output of a console.
Write your first line of code
There’s a long-standing tradition among software developers to print the phrase “Hello World!” to the console output window. As you’ll experience, you can learn a lot about programming and the C# programming language from this simple exercise.
Enter code into the .NET Editor
The .NET Editor and output console provide a great in-browser experience that’s perfect for this tutorial approach. The .NET Editor is located on the right-hand side of this web page. The output console is below it.
- Enter this code exactly as it appears into the .NET Editor on the right:C#Copy
Console.WriteLine("Hello World!");
You’ll see an explanation of how and why it works soon. But first, you should experience it running, and ensure you entered it correctly. To do that, you’ll run your code. NoteYou might be tempted to selectCopy
orRun
and skip all the keystrokes. However, there are benefits to typing code yourself. Entering the code yourself reinforces memory and understanding that will help you gain insights that you wouldn’t get otherwise.
Run your first code
- Press the green Run buttonThe green Run button performs two tasks:
- It compiles your code into an executable format that a computer can understand.
- It runs your compiled application and, when written correctly, will output
"Hello World!"
.