Contents

Kata 2

Overview

In this Kata we’ll install everything we need in order to start writing computer software in the C# programming language. You’ll then learn how to execute the simplest, yet possibly most important application you’ll ever write - the ‘Hello World!’.

Setup

  • Get access to a computer running Windows 10
  • Get access to a text editor
    • I strongly suggest you use Visual Studio Code - often shortened to VSCode - as you work through this book
    • Install VSCode
  • Install the .Net Core SDK .Net Core is a software development toolkit provided by Microsoft. It allows you to write software in several different programming languages, and is accessible through a simple command line interface.

Kata Instructions

When you create a computer program, you’ll end up creating alot of files. Therefore you’ll need to prepare a place on your computer where you would like to store the files related to your program. Therefore, the best thing to do is create an empty folder to work in.

Open the start menu and type cmd to open Windows Command Prompt. Use cd to navigate to a place on your computer where you would like your folder to live.

This can be anywhere at all on your computer. A good place is usually the Documents folder. So you might use something like:

cd C:\Users\Mikiel\Documents

Use mkdir create a new folder. For instance:

mkdir MyWorkspace

This will create a new folder called MyWorkspace.

Navigate into the folder using cd. For instance:

cd MyWorkspace

In the Command Prompt Window, write:

dotnet new console -o App

This will create a new folder, App, and place some files in that folder for you.

The dotnet command is provided by the ‘Net Core SDK that you installed earlier.

Hello Visual Studio Code!

As I said before, I recommend you use Visual Studio Code (VSCode) to work through this book. This is because it has an integrated Command Prompt console, which makes things much simpler. VSCode is also quickly growing in popularity, so it’s a good text editor to learn if you want to be up to date!

Open VSCode from the start menu and select File -> Open Folder...

Find the folder you created in the Command Prompt and open it.

In the left hand side of the VSCode window, there should be an icon called ‘Explorer’. Click on this to see the files that are in the folder you just created. It should look something like this:

image

Note that you may need to expand App since it’s a folder. Do this by clicking on it in the Explorer.

You can ignore App.csproj and the obj folder and it’s contents for now. What we’re interested in is Program.cs. This is where we’ll write our first program.

Open Program.cs in VSCode by double clicking on it in the Explorer. You should see something like this:

using System;

namespace App
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

The dotnet command that we ran has automatically generated a program for us!

Running the program

Let’s run this program and see what it does.

If you’re using VSCode, now is a good time to open up the integrated terminal. At the top of the VSCode window, click Terminal -> New Terminal. You should see a terminal window appear at the bottom of your screen. You can now type Command Prompt commands here like before.

Navigate into the App folder in the Command Prompt using cd. For instance:

cd App

To run the program, just run:

dotnet run

The dotnet run command will compile Program.cs into an an executable format - and then execute it.

The Command Prompt should then display the following:

Hello world!

You may notice that a new folder has been created, bin. This can also be ignored for now. I’m just telling you this so you know it hasn’t appeared by magic.

Finished!

And that’s it! You’ve just created and run your first computer program! You’ve also been acquainted with the .NET Core command line interface, and VSCode. Although you haven’t written any code by yourself, you’ve laid the groundwork that will enable you to write your own computer programs.

Completed Katas

There are examples of completed Code Katas available. Use these when you get stuck to find out where you’re going wrong. You can learn more about the completed Katas in the Appendix, which you can find through the table of contents.

Copyright Mikiel Agutu 2019