Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> C Language

C# Hello World: Building Your First Console Application

C# is a powerful, object‑oriented language built on Microsoft’s .NET framework, enabling developers to create a wide range of applications from desktop to web services.

This tutorial walks you through building your very first console program – a classic “Hello World” – using Visual Studio. By the end, you’ll understand the project structure, key C# concepts, and how to run a console app.

Creating the Console Application

A console application runs directly in the Windows command prompt, making it an ideal starting point for .NET beginners.

We’ll use Visual Studio to scaffold a new project, then add a simple Console.Write statement to output text. Follow these steps:

Step 1: Create a New Project

Open Visual Studio and choose New → Project….

C# Hello World: Building Your First Console Application

Step 2: Select the Project Type

In the dialog, pick Windows → Console App, give the project a name (e.g., DemoApplication), choose a location, and click OK.

C# Hello World: Building Your First Console Application

  1. Navigate the left pane to Windows.
  2. Select Console App.
  3. Enter a project name and location.
  4. Confirm with OK.

Visual Studio will create the project structure. You’ll see a file called Program.cs – the default entry point for the app.

Step 3: Add Your First Code

Replace the content of Program.cs with the following snippet:

C# Hello World: Building Your First Console Application

C# Hello World Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Hello World");
            Console.ReadKey();
        }
    }
}

Explanation

  1. using directives import essential .NET namespaces.
  2. All executable code lives inside a class – here Program – which itself is grouped into the DemoApplication namespace.
  3. The Main method is the entry point that runs automatically when the application starts.
  4. Console.Write outputs text to the console window.
  5. Console.ReadKey pauses execution until the user presses a key, preventing the window from closing immediately.

Step 4: Build and Run

Click the Start button (or press F5) to build and launch the program. You should see the following output:

C# Hello World: Building Your First Console Application

The console displays “Hello World”, confirming that your first C# console application is working.

Summary

C Language

  1. C# Hello World – Building Your First C# Application
  2. Java Hello World: Your First Program
  3. How Acid Dyes Transform Fabrics: Applications & Benefits
  4. Your First VHDL Program: A Step‑by‑Step Hello World Tutorial
  5. C++ Hello World Tutorial: Step‑by‑Step Code, Setup & Explanation
  6. C Hello World: Your First Program – A Step‑by‑Step Guide
  7. Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program
  8. Hello World: Building Your First Python Application
  9. Beginner’s Guide to Verilog: Hello World Example
  10. First CNC Program: Step-by-Step CNC Machining Guide