Writing Your First .NET Framework Application

This guide will walk you through the steps to create a simple "Hello, World!" application using the .NET Framework. This is a foundational step for anyone starting with .NET development.

Prerequisites

Before you begin, ensure you have the following installed:

Step 1: Create a New Project

Open Visual Studio and follow these steps:

  1. Go to File > New > Project...
  2. In the "Create a new project" dialog, search for "Console App".
  3. Select the "Console App (.NET Framework)" template and click Next.
  4. Give your project a name (e.g., HelloWorldApp) and choose a location. Click Create.

Step 2: Write the Code

Visual Studio will create a basic project structure. Locate the Program.cs file and replace its content with the following code:

using System;

            namespace HelloWorldApp
            {
                class Program
                {
                    static void Main(string[] args)
                    {
                        // Display a message to the console
                        Console.WriteLine("Hello, World!");

                        // Keep the console window open until a key is pressed
                        Console.WriteLine("Press any key to exit...");
                        Console.ReadKey();
                    }
                }
            }
            

Code Explanation:

Step 3: Build and Run the Application

Now you can build and run your application:

  1. Click the Start button (a green triangle) on the Visual Studio toolbar, or press F5.
  2. Alternatively, you can build the project by going to Build > Build Solution (or Ctrl+Shift+B) and then run the executable from the output directory (usually in bin\Debug or bin\Release within your project folder).
Congratulations! You have successfully written, built, and run your first .NET Framework application.

Next Steps

Now that you've created your first application, you can explore more advanced topics: