NewsArticles

How to write First C# program?

To write your first C# program, you’ll need to follow these steps:

  1. Install Visual Studio (optional): While it’s not strictly necessary, using an integrated development environment (IDE) like Visual Studio can make the process smoother. You can download Visual Studio Community edition for free from the official Microsoft website: https://visualstudio.microsoft.com/
  2. Create a new project:
    • Open Visual Studio.
    • Click on “Create a new project.”
    • Choose a template based on your requirements (Console Application is suitable for a simple first program).
    • Give your project a name and location.
    • Click “Create.”
  3. Write your first C# code:
    • In Visual Studio, you’ll see a file named Program.cs open by default.
    • Replace the existing code with a simple “Hello, World!” program:

using System;

class Program
{
static void Main()
{
Console.WriteLine(“Hello, World!”);
}
}

  1. Run your program:
    • Save your changes (Ctrl + S).
    • Click on the “Start” button (green arrow) or press F5 to build and run your program.
  2. View the output:
    • You should see the output in the console window, displaying “Hello, World!”

Congratulations! You’ve just written and run your first C# program. This basic example introduces you to the structure of a C# program, including the Main method, Console.WriteLine for output, and the basic syntax. As you continue, you can explore more advanced features and concepts in the C# language.

Leave a Comment