Earn More by Sharing What You Love
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!

Layla Porter
9m 9s
C# is a versatile and powerful programming language developed by Microsoft. In this guide, we'll walk through the basics of C# programming, inspired by the video tutorial, 'C# for Beginners part 1 - Learn how to install .NET and start coding' by LaylaCodesIt. We'll cover everything that Layla does - from setting up your development environment to writing and understanding your first C# program.
C# is a modern, object-oriented programming language designed for building a wide range of applications that run on the .NET framework. It is known for its simplicity, versatility, and robustness, making it a popular choice for both beginners and experienced developers.
Before we can start coding in C#, we need to set up our development environment. Layla starts with the following steps to set up the complete environment for C# development.
First, we need to install the .NET SDK (Software Development Kit). This is essential for compiling and running C# applications.
To verify the installation (1:14):
dotnet and press Enter. If installed correctly, you'll see a list of available commands.dotnet --list-sdks.An IDE is a piece of software which provides developers with a single, flexible space to edit, test, and build their applications. At 2:47, Layla suggests using Visual Studio Code (VS Code), a free, cross-platform code editor - a good option to begin with. Once you're more comfortable with coding, you can switch to more extensive platforms like Visual Studio and JetBrains Rider.
You need a directory to store your project files:
C:\users\your-username\source\repos as seen in the video at 3:16, where Layla shows how to create a folder named new-code. You can create your project folder anywhere.With the environment set up, let's write a simple C# program. Follow these steps as demonstrated in the video to get your hands on your first C# program.
Using the terminal in Visual Studio Code:
cd path/to/new-codedotnet new consoleAfter creating the new project, you'll notice several files in your folder:
Open Program.cs and you'll see a simple C# program:
// This line outputs "Hello, World!" to the console.
Console.WriteLine("Hello, World!");' This line outputs "Hello, World!" to the console.
Console.WriteLine("Hello, World!")To run the program (6:05):
dotnet run.Hello, World!Let's make the program interactive:
The following example asks the user their name and greets them:
// Asks the user for their name
Console.WriteLine("Hello, what is your name?");
// Reads input from the user
string name = Console.ReadLine();
// Greets the user with the entered name
Console.WriteLine($"Hey {name}, nice to meet you!");' Asks the user for their name
Console.WriteLine("Hello, what is your name?")
' Reads input from the user
Dim name As String = Console.ReadLine()
' Greets the user with the entered name
Console.WriteLine($"Hey {name}, nice to meet you!")Save the changes and run the program again with dotnet run.
In the past, C# programs followed a more rigid structure with several key elements:
These organize code into logical categories. You'd typically see using System; at the beginning, which brings in commonly used functionalities.
C# is object-oriented and code is organized within classes. A class is like a blueprint for creating objects.
This is the entry point of your program. Execution starts here. It has a specific signature: static void Main(string[] args).
Reusable blocks of code that perform specific tasks. They can take arguments and return values of different data types.
These form the core instructions within your program, manipulating data and controlling flow of C# code.
More recent versions of C# (C# 6 and above) introduced top-level statements. This allows you to write C# code directly in a .cs file without the need for a class or Main method as demonstrated by Layla in the video. Here's how it changes things:
Top-level statements are an alternative to class-based coding for simple programs which don't require complex object-oriented features. If you're just starting out with C#, this is an easier and simpler way to code while you learn.
With top-level statements, you can skip the need for a Main Method. Instead, the first executable line in your file becomes the entry point for the class program.
Congratulations! You've set up your C# development environment, written, and understood your first C# program. As mentioned before, this guide was inspired by LaylaCodesIt - check out her channel for video demonstrations of everything above and for more information on C# programming.
In the meantime, check out our other resources where we share our favorite creators, tutorials, and learning resources to level up your C# skills. Happy coding!
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!
Join our newsletter, you’ll get exclusive access on article updates. We value your privacy