C# Programming Introduction

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
.NET · Console · Main()

What You’ll Learn

This page is a self-contained introduction to C# (pronounced “C sharp”)—no prior coding experience required. You will understand what C# is, write your first console program, and learn how .NET runs your code.

01

What is C#

Modern .NET lang.

02

History

Microsoft & .NET.

03

Hello World

First program.

04

dotnet run

Run locally.

05

Open source

Roslyn compiler.

06

Building blocks

Core concepts.

🤔 What is C# Programming?

C# is a modern, multi-paradigm programming language developed by Microsoft. It is designed to be simple, efficient, and type-safe. Developers use it to build Windows desktop apps, web APIs with ASP.NET, cloud services on Azure, games with Unity, and cross-platform mobile apps with .NET MAUI.

C# is an object-oriented language. You organize code into classes and objects, which makes large applications easier to maintain, test, and extend. The .NET runtime manages memory for you through garbage collection, so you focus on logic rather than manual allocation.

💡
Beginner tip

Start with small console programs using Console.WriteLine and if/for. Once those feel natural, move on to classes, lists, and async code.

👤 Who Created C#?

Anders Hejlsberg is widely considered the father of C#. The Danish computer scientist led the team at Microsoft that designed C# in the late 1990s, with the first release shipping alongside .NET in the early 2000s. The goal was a modern, object-oriented language for the Microsoft ecosystem that felt familiar to C++ and Java developers.

Since then, C# has evolved through many versions with generics, LINQ, async/await, records, and more. The timeline below highlights major milestones.

Version / EventYearHighlight
C# announced2000Anders Hejlsberg, Microsoft
C# 1.0 + .NET 1.02002First public release
C# 2.02005Generics, nullable types
C# 3.02007LINQ, lambda expressions
C# 5.02012async / await
Roslyn open source2014Compiler on GitHub
.NET Core2016Cross-platform .NET
C# 9.02020Records, top-level statements
C# 122023Primary constructors, collection expressions

🔓 Is C# Open Source?

Yes. C# and .NET are open source. The Roslyn compiler, large parts of the runtime, and the base class libraries are available on GitHub under permissive licenses (MIT and similar). Developers can use, study, modify, and contribute to the platform freely.

You do not need Windows to write C# today—install the .NET SDK on Linux, macOS, or Windows and use VS Code, Visual Studio, or JetBrains Rider.

📝 Program Structure & Syntax

A classic C# console program includes a using directive, a class, and a Main method as the entry point:

C#
using System;

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

Syntax rules

  • using System; — imports the System namespace so you can use Console and other core types.
  • class — defines a type that groups methods and data (object-oriented design).
  • static void Main — entry point; the runtime calls this method when the program starts.
  • Console.WriteLine — prints a line of text to the terminal.
  • Semicolons — end statements; braces { } define blocks.
  • Top-level statements — newer templates allow shorter Program.cs without an explicit class; both styles are valid.

💻 How to Create and Run a C# Program

Install the .NET SDK, then create a console project from a terminal:

C#
dotnet new console -n HelloApp
cd HelloApp
dotnet run
  • dotnet new console — scaffolds a project with Program.cs and a .csproj file.
  • dotnet run — compiles and executes in one step (great while learning).
  • dotnet build — compile only; useful before deployment.
  • IDEs — Visual Studio, VS Code with C# Dev Kit, or JetBrains Rider provide IntelliSense and debugging.

🧰 Core Building Blocks

As you continue learning C#, these are the main ideas you will encounter:

ConceptWhat it does
Types & variablesint, double, string, bool, and more
Control flowif, else, switch, loops
MethodsReusable functions inside classes
Classes & objectsEncapsulate data and behavior (OOP)
PropertiesClean getters/setters for fields
CollectionsList<T>, arrays, dictionaries
LINQQuery collections with readable syntax
async / awaitNon-blocking I/O and responsive apps

⚡ Quick Reference

TaskExample
Print lineConsole.WriteLine("Hi");
Read linestring s = Console.ReadLine();
Parse integerint n = int.Parse(input);
Conditionif (x > 0) { ... }
for loopfor (int i = 0; i < n; i++) { ... }
String interpolate$"Age: {age}"

Examples Gallery

Five starter console programs. Create a project with dotnet new console, paste into Program.cs (adjust class structure if needed), and run with dotnet run.

Example 1 — Hello, World!

C#
using System;

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

Console.WriteLine() outputs text. Main() is where execution begins. using System; imports core types including Console.

Example 2 — Variables and output

C#
using System;

class Vars
{
    static void Main()
    {
        int age = 20;
        double gpa = 3.85;
        char grade = 'A';
        string name = "Alex";

        Console.WriteLine($"Name: {name}");
        Console.WriteLine($"Age: {age}");
        Console.WriteLine($"GPA: {gpa:F2}");
        Console.WriteLine($"Grade: {grade}");
    }
}

Example 3 — Reading user input

C#
using System;

class InputDemo
{
    static void Main()
    {
        Console.Write("Enter a number: ");
        string text = Console.ReadLine();
        int num = int.Parse(text);
        Console.WriteLine($"You entered: {num}");
    }
}

In production code, prefer int.TryParse to handle invalid input safely.

Example 4 — A simple method

C#
using System;

class AddDemo
{
    static int Add(int a, int b)
    {
        return a + b;
    }

    static void Main()
    {
        Console.WriteLine($"Sum = {Add(3, 5)}");
    }
}

Example 5 — Even or odd with if-else

C#
using System;

class EvenOdd
{
    static void Main()
    {
        Console.Write("Enter n: ");
        int n = int.Parse(Console.ReadLine());

        if (n % 2 == 0)
            Console.WriteLine($"{n} is even");
        else
            Console.WriteLine($"{n} is odd");
    }
}

📚 Why Learn C#?

  • Versatile career path — web, desktop, games, cloud, and enterprise backends.
  • Strong tooling — IntelliSense, debugging, and NuGet packages speed up development.
  • Type safety — catch many errors at compile time before users see them.
  • Modern language — regular updates add productivity features without breaking the ecosystem.
  • Cross-platform .NET — deploy the same skills on Windows, Linux, and macOS.
  • Unity & games — one of the most popular languages for indie and AAA game scripting.

📋 C# vs Other Languages

LanguageRuntimeBest for beginners when…
C#.NET (CLR)You want OOP, tooling, and Microsoft/Azure ecosystem skills
JavaJVMYou target Android or enterprise JVM stacks
PythonInterpreterYou want the fastest path to scripts and data science
C++NativeYou need maximum performance and systems control

🧠 How a C# Program Runs

1

Write C# source (.cs)

You create classes, methods, and a Main entry point (or top-level statements).

Edit
2

Compile to IL

Roslyn compiles C# to Intermediate Language (IL) packaged in an assembly.

Compile
3

CLR executes

The .NET runtime (CLR) JIT-compiles IL to native code and manages memory.

Runtime
=

Output appears

Main runs; Console.WriteLine prints to the terminal.

Summary

  • C# (C sharp) is a modern, type-safe language created by Anders Hejlsberg at Microsoft.
  • It is object-oriented and runs on the cross-platform .NET runtime.
  • C# and Roslyn are open source with an active community.
  • Programs use using, classes, Main, and Console for basic I/O.
  • Run locally with dotnet new console and dotnet run.
  • The # symbol is the “sharp” in the name—like musical notation for a half-step higher.

💡 Best Practices

✅ Do

  • Use meaningful names (studentCount, not x)
  • Prefer int.TryParse over bare int.Parse for user input
  • Brace every if and loop body for clarity
  • Run dotnet build and fix warnings early
  • Type out examples yourself—muscle memory matters
  • Read compiler errors from the first line downward

❌ Don’t

  • Ignore null reference warnings in modern C# projects
  • Compare strings with == when culture matters (use Equals with options)
  • Put all logic inside Main forever—split into methods and classes
  • Skip understanding basic OOP before frameworks like ASP.NET
  • Copy code without knowing what each line does
  • Assume C# only runs on Windows—.NET is cross-platform

❓ Frequently Asked Questions

C# (pronounced "C sharp") is a modern, multi-paradigm language from Microsoft. It is type-safe, object-oriented, and runs on .NET. Developers use it for web APIs, desktop apps, games with Unity, cloud services, and mobile apps with .NET MAUI.
Yes. C# has clear syntax, helpful compiler messages, and strong tooling in Visual Studio and VS Code. It teaches object-oriented concepts while staying approachable. Many schools and bootcamps use C# for first-year programming courses.
Install the .NET SDK, then run: dotnet new console -n HelloApp, cd HelloApp, dotnet run. Paste the hello world code into Program.cs. You can also use online C# runners if you cannot install the SDK yet.
Yes. The C# compiler (Roslyn), the .NET runtime, and much of the platform are open source under permissive licenses. Microsoft and the community maintain them on GitHub through the .NET Foundation.
Practice variables, if-else, loops, and methods in small console programs. Then learn classes and objects, collections, exception handling, and LINQ. Build habits early: use meaningful names, handle parse errors, and read compiler messages carefully.
Both are object-oriented and run on managed runtimes (.NET vs JVM). C# integrates tightly with Windows and Azure but is cross-platform via .NET. Syntax is similar; C# adds features like properties, LINQ, and async/await with slightly different keywords.
Did you know?

The # symbol in C# is the musical “sharp” sign—raising a note by a half step. That is how the language got its name: C raised one step, suggesting an evolution beyond C and C++. If you know C-style syntax, many C# basics will feel familiar on day one.

Try It Yourself

Install the .NET SDK, create a console app, and run the hello world example from this page.

Get .NET SDK →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful