Running Your First C# Program

Developing and running your first C# program is a straightforward process, especially when using an IDE like Visual Studio. Here are the steps to create, compile, and run a simple "Hello World" application using Visual Studio.

Step 1: Install Visual Studio

The first step is to download and install Visual Studio on your computer. You can download the Community edition of Visual Studio, which is free for individual developers, open-source projects, academic research, education, and small professional teams.

Step 2: Create a New Project

Once Visual Studio is installed, open it and select "Create a new project". In the "Create a new project" window, type "Console" in the search box. Find "Console App (.NET Core)" in the template panel and click "Next".

Provide a name for your project and select a location to save it. After entering these details, click "Create".

Step 3: Write Your First C# Program

Visual Studio will create a new console application project and open the Program.cs file. You'll see that some basic C# code has already been written for you:

using System;

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

This simple program writes the text "Hello World!" to the console.

Step 4: Run the Program

To run the program, you can press F5 (Debug Start) or Ctrl+F5 (Start Without Debugging). A console window will open that displays the output of your program: "Hello World!".

Congratulations! You've just created and run your first C# program.

Understanding the Code

Here's a quick overview of what the provided code means:

  • using System; - This is a using directive that allows you to use classes from the System namespace without having to fully qualify them in your code. For example, you can write Console instead of System.Console.
  • namespace HelloWorld - This defines a namespace for your program. A namespace is a way to group related code and avoid name collisions with other pieces of code that may have the same names for their classes, methods, etc.
  • class Program - This declares a class named Program. A class is a blueprint for creating objects in object-oriented programming.
  • static void Main(string[] args) - This declares the Main method, the entry point of your program. The static keyword means that the method belongs to the Program class itself, not an instance of the Program class. The void keyword means that the method does not return any value.
  • Console.WriteLine("Hello World!"); - This is a method call that writes the string "Hello World!" to the console.

Optional

If you have had much experience in JavaScript, you guys can try to create a ASP.NET Core MVC CRUD project if not you can download this source.
Reference video: .NET 6 MVC CRUD Operation Using Entity Framework Core and SQL Server

Complete and Continue  
Discussion

0 comments