Getting Started with C#: Your First "Hello, World!" Program
Welcome to the world of C#, a powerful and expressive programming language developed by Microsoft. If you're new to C#, the best way to start your learning journey is by creating a simple "Hello, World!" program. This article will guide you through creating, compiling, and running your first C# application, ensuring you understand the basics of this versatile language.
Setting Up Your Development Environment
Before you dive into coding, you need to set up your development environment. If you're using Windows, you can install the free Visual Studio Community edition, which comes with a robust code editor and a built-in compiler. Mac users can use Visual Studio Code, a lightweight yet powerful code editor, along with the .NET SDK for compiling and running C# applications.
Installing Visual Studio Community (Windows)
- Download and install Visual Studio Community from the official Microsoft website.
- During installation, make sure to select the ".NET desktop development" workload.
Installing .NET SDK (Mac)
- Download and install the .NET SDK from the official Microsoft website.
- Verify the installation by opening a terminal and typing `dotnet --info`.
Creating Your First C# Console Application
Now that your development environment is set up, let's create a simple console application that displays "Hello, World!"

Using Visual Studio Community (Windows)
- Open Visual Studio and click on "Create a new project".
- Select "Console App (.NET Framework)" and click "Next".
- Name your project "HelloWorld", choose a location to save it, and click "Create".
Using Visual Studio Code (Mac)
- Open Visual Studio Code and create a new folder named "HelloWorld".
- Open a terminal in the "HelloWorld" folder and run `dotnet new console -n HelloWorld`.
Writing Your First C# Code
Now that you have a new project, it's time to write your first C# code. Open the "Program.cs" file in your project. You'll see some existing code; don't worry, we'll replace it with our own.
Here's the simple C# code that will display "Hello, World!" in the console:
```csharp using System; class HelloWorld { static void Main() { Console.WriteLine("Hello, World!"); } } ```
Let's break down this code:

using System;- This line imports the System namespace, which contains the Console class we'll use to display output.class HelloWorld { }- This defines a class named "HelloWorld". In C#, every application must have at least one class with a Main method.static void Main() { }- This is the entry point of your application. The code inside this method will run when you execute your program.Console.WriteLine("Hello, World!");- This line displays the text "Hello, World!" in the console.
Compiling and Running Your Application
Now that you've written your code, it's time to compile and run your application.
Using Visual Studio Community (Windows)
- Press Ctrl + F5 to build and run your application.
- You should see a console window displaying "Hello, World!".
Using Visual Studio Code (Mac)
- Open a terminal in the "HelloWorld" folder and run `dotnet run`.
- You should see a console window displaying "Hello, World!".
Conclusion and Next Steps
Congratulations! You've just created, compiled, and ran your first C# application. This simple "Hello, World!" program is a great starting point for learning C#. From here, you can explore more features of the language, such as variables, data types, loops, and functions. Happy coding!























