Skip to content

Your First Program

Here are the steps needed to build your own program:

  1. Create a new folder for the project, and move into this in the terminal
  2. Use dotnet new console to create the initial project files
  3. Add the SplashKit package we will be using dotnet add package splashkit
  4. Write the code in Program.cs
  5. Build and run using dotnet run

Let’s go through these steps to build a simple terminal-based program to output the text: “Hello, World”.

Make sure you are set up

We need somewhere to put our project’s code. For this, we will create a folder in our Documents/Code folder. You should have created this folder as part of the tour in the Computer Use chapter, but we will repeat it here just in case you missed that step.

You can choose anywhere to store your code, if you want to save your code elsewhere then make sure to adjust paths as needed. Open a terminal, and use the following commands to create the Documents/Code folder:

Terminal window
# Create a Documents/Code folder
# Windows users -see the following note
mkdir ~/Documents/Code
# Move to the Documents/Code folder
cd ~/Documents/Code

Create the project folder

Now you can create a folder for your project. Make sure you are in your Documents/Code folder, and run the following commands:

Terminal window
# Make a folder for the project
mkdir HelloWorld
# Move into that folder
cd HelloWorld

Create dotnet project files

We will be using C# initially, for these programs we need to setup project files that the language uses to know how to build your program.

To create the initial project files for this C# program, copy and paste the following commands into your Terminal window:

Terminal window
dotnet new console
dotnet add package splashkit

This creates the project, and add the splashkit library we will be using.

If you run ls -lha in the terminal after the commands above, it should look similar to this:

A terminal window showing the above commands being used.

Image not subject to The Programmer's Field Guide CC BY-NC-ND 4.0 License

Now you are ready to start coding your first program!

Write your code

From the terminal window, we can open the current folder in Visual Studio Code using the following command:

Terminal window
code .

You will notice that shortly after opening the project, a bin folder and a .sln file will be added automatically:

A VS Code window showing the files in the Explorer tab.

Image not subject to The Programmer's Field Guide CC BY-NC-ND 4.0 License

Open Program.cs file (shown above in Green box) by double-clicking the file in the Explorer tab (shown above in Orange box):

Copy the following code into your Program.cs file (replacing the existing code):

using static SplashKitSDK.SplashKit;
WriteLine("Hello, World!");

After the last line, you can add another WriteLine("...") bit of code with your own custom message!

Build and run your code

Let’s turn your code into a program! Like magic!

Use the following command to build and run the program:

Terminal window
dotnet run

Here is what the result will look like:

A VS Code window showing the program being run in the terminal.

Image not subject to The Programmer's Field Guide CC BY-NC-ND 4.0 License

Next, we are going to create a Graphical Hello World program!