</>
Skip to content
C# lessons (3/34)

C# — Get Started

What is C#?

C# (pronounced "C sharp") is a modern, object-oriented language developed by Microsoft. It runs on the .NET platform and is used for Windows apps, web APIs, games (Unity), mobile apps (Xamarin), and cloud services (Azure).

Created by Anders Hejlsberg in 2000, C# combines C++ power with Java-like simplicity.

Install .NET

  1. Go to dotnet.microsoft.com
  2. Download the .NET SDK
  3. Install and verify:
dotnet --version

Your first program

dotnet new console -n HelloWorld
cd HelloWorld
dotnet run

Output:

Hello, World!

The project creates a Program.cs file:

Console.WriteLine("Hello, World!");

That's it — no class boilerplate needed. Modern C# (top-level statements) is remarkably clean.

The traditional structure

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
        }
    }
}
  • using System — import the System namespace
  • namespace — organizes code
  • class Program — every C# file contains classes
  • static void Main — entry point
  • Console.WriteLine — prints to the console

Output

Console.WriteLine("Hello");           // prints with newline
Console.Write("Hello");              // no newline
Console.Write("World\n");            // explicit newline

// String interpolation
string name = "Ada";
int age = 36;
Console.WriteLine($"Hello, {name}! You are {age} years old.");

The $ prefix enables string interpolation — embed variables directly in strings with {}.

Input

Console.Write("Enter your name: ");
string name = Console.ReadLine();

Console.Write("Enter your age: ");
int age = int.Parse(Console.ReadLine());

Console.WriteLine($"Hello, {name}! Age: {age}");

Console.ReadLine() returns a string. Parse it to get a number.

Variables

int age = 36;              // integer
double pi = 3.14159;       // double precision
float price = 9.99f;       // single precision
char letter = 'A';         // single character
string name = "Ada";       // string
bool active = true;        // boolean

var x = 42;                // type inferred

C# is statically typed — the compiler checks types at compile time.

var keyword

var name = "Ada";          // string
var age = 36;              // int
var pi = 3.14;             // double
var numbers = new[] {1, 2, 3};  // int[]

var lets the compiler infer the type. Use it when the type is obvious from the right side.

Constants

const int MAX_SIZE = 100;
const double PI = 3.14159;

const values are immutable and must be assigned at declaration.

Comments

// Single-line comment

/* Multi-line comment
   spans several lines */

/// <summary>
/// Documentation comment for XML docs.
/// </summary>

C# uses XML documentation comments (///) for generating reference docs.

The .NET ecosystem

ComponentPurpose
.NET SDKBuild and run C# programs
NuGetPackage manager
ASP.NETWeb framework
Entity FrameworkDatabase ORM
UnityGame engine
MAUICross-platform apps

Project structure

MyProject/
  MyProject.csproj    # project file
  Program.cs          # entry point
  bin/                # compiled output
  obj/                # build intermediates

Common commands:

dotnet new console        # create new console project
dotnet build              # compile
dotnet run                # compile and run
dotnet add package NAME   # add a NuGet package
dotnet test               # run tests

Mini Practice

  1. Install .NET and verify with dotnet --version
  2. Create a new console project and run it
  3. Write a program that reads a user's name and age, then prints a greeting
  4. Use string interpolation to format output
  5. Create a constant and use it in a calculation

Next: C# syntax rules →

Related Topics

Frequently Asked Questions about Get Started

What is Get Started in C#?

Get Started is a fundamental concept in C#. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Get Started?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Get Started.

Why is Get Started important in C#?

Get Started is essential for C# development. Understanding this concept will help you write better code and solve real-world problems more effectively.