Introduction
C# is a modern, object-oriented programming language developed by Microsoft that runs on the .NET platform and is widely used to build web apps, desktop software, games (with Unity), and cloud services.
Part of the free C# course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
By the end of this lesson you'll understand what C# and .NET are, you'll have written and run your own C# program, and you'll be printing clean, formatted output with Console.WriteLine and string interpolation — the very first skills every C# developer needs.
What You'll Learn
💡 Real-World Analogy
Think of C# as a universal remote control . Just like one remote can control your TV, sound system, and streaming box, C# can build desktop apps, websites, mobile apps, and games — all with the same language. The .NET framework is the signal receiver that makes everything work together. You learn one "remote" and control an entire ecosystem.
What is C# and .NET?
C# (pronounced "C Sharp") is a modern, object-oriented programming language created by Microsoft in 2000. It was designed by Anders Hejlsberg (who also created TypeScript and Delphi) to be powerful yet approachable — combining the performance of C++ with the productivity of languages like Java and Python.
C# runs on the .NET platform , which provides a massive standard library, a garbage collector for automatic memory management, and cross-platform support. With .NET 8+, your C# code runs on Windows, macOS, and Linux. Here's what you can build:
- 🎮 Games — Unity (the world's most popular game engine) uses C# exclusively
- 🌐 Web APIs & Websites — ASP.NET Core powers enterprise backends at Microsoft, Stack Overflow, and more
- 🖥️ Desktop Apps — Windows Forms, WPF, and .NET MAUI for cross-platform UIs
- 📱 Mobile Apps — .NET MAUI and Xamarin for iOS/Android from a single codebase
- ☁️ Cloud & Microservices — Azure Functions, gRPC services, and containerised APIs
C# is consistently ranked in the top 5 most in-demand programming languages, with average salaries ranging from £35,000–£75,000 (UK) and $60,000–$130,000 (US) depending on specialisation.
📊 C# Program Anatomy
Part
Code
What It Does
Using directive
using System;
Imports the System namespace so you can use Console
Class declaration
class Program {}
Every C# program lives inside a class
Main method
static void Main()
The entry point — where your program starts running
Statement
Console.WriteLine("...");
An instruction that does something — ends with ;
String interpolation
$"Hello {name} "
Embed variables inside strings with $ prefix
🖥️ Setting Up C#
You can practise C# right here in the browser, but to run C# on your own machine:
Option 1: Visual Studio (Recommended for Windows)
- Download Visual Studio Community (free) from visualstudio.microsoft.com
- Select the ".NET desktop development" workload during installation
- Create a new "Console App" project and start coding
- Install the .NET SDK from dotnet.microsoft.com
- Install VS Code with the C# extension
- Run dotnet new console -n MyApp in terminal, then dotnet run
Use dotnetfiddle.net or the code editors in this course to practise instantly.
1. Your First C# Program
Every C# journey starts with "Hello, World!". Console.WriteLine() prints text to the console and then moves to a new line. The text you want to print goes inside "double quotes" , and the whole statement ends with a semicolon ; . Read this worked example first and run it, then you'll write your own.
Your turn. The program below is almost complete — fill in the two blanks marked ___ with your own text (remember the "double quotes"), then run it.
2. Console Output & String Interpolation
Console.Write() prints without a new line, so the next output continues on the same line, while Console.WriteLine() finishes the line for you. String interpolation — the $"..." syntax — lets you drop variables straight into text inside { curly braces } , which reads far better than gluing strings together with + . Escape characters like \n (new line) and \t (tab) let you shape the layout.
Now you try. Fill in the two blanks: one puts a variable inside interpolation braces, the other prints a number on the same line as some text.
3. A Taste of Variables
Variables store data. C# is strongly typed , which means every variable has a specific type ( string , int , double , bool ) that fixes what it can hold. You'll cover types in depth in the very next lesson, but here's a preview so the next lesson feels familiar:
Pro Tips
- 💡 C# is case-sensitive: Console works, console doesn't. Watch your capitalisation.
- 💡 Every statement ends with a semicolon (;) — forgetting it is the most common beginner error.
- 💡 Use string interpolation ($"...") instead of concatenation ("Hello " + name). It's cleaner and easier to read.
- 💡 C# 9+ supports top-level statements: you can skip the class and Main method for simple programs. But learn the full structure first — you'll need it for real projects.
Common Errors (and the fix)
- "CS1002: ; expected" — you forgot the semicolon at the end of a statement. Every statement must end with ; , e.g. Console.WriteLine("Hi"); .
- "CS0103: The name 'Console' does not exist in the current context" — you're missing using System; at the top, so the compiler doesn't know what Console is. Add that line.
- "CS0234: The type or namespace name '…' does not exist in the namespace 'System'" — a using points at something that isn't there (a typo or a missing package). Check the namespace spelling.
- "CS0117: 'Console' does not contain a definition for 'Writeline'" — wrong capitalisation. It must be Console.WriteLine with a capital L ; C# is case-sensitive.
- "CS1525 / CS1056: Unexpected/invalid token" — usually a mismatched brace. Every { needs a matching } ; use an editor that highlights matching braces.
- "CS1012: Too many characters in character literal" — you used 'single quotes' around text. Strings use "double quotes" ; single quotes are only for one char like 'A' .
📋 Quick Reference
Task
Result
Print a line
Console.WriteLine("Hi");
Hi (then new line)
Print, no new line
Console.Write("Hi");
Hi (cursor stays)
Interpolation
$"Hi {name}"
Hi Sam
New line inside text
"Line1\nLine2"
two lines
Tab inside text
"A\tB"
A B
Import for Console
enables Console
Frequently Asked Questions
Q: What's the difference between Console.Write and Console.WriteLine ?
WriteLine prints your text and then moves to a new line. Write prints your text but leaves the cursor right after it, so the next output continues on the same line.
Console lives in the System namespace. The using System; line tells the compiler where to find it. Leave it out and you get CS0103: The name 'Console' does not exist .
Q: Do I really have to write the class and Main every time?
Modern C# (9+) supports "top-level statements" that let you skip them for small programs. But the full structure is what real projects use, so it's worth learning first — that's why this course shows it.
Q: Why did my code break when I typed console.writeline ?
C# is case-sensitive. It must be Console.WriteLine with the capital C , W , and L . Capitalisation is part of the name, not a style choice.
Mini-Challenge: "About Me" Banner
No blanks this time — just a brief and a blank canvas (with a comment outline to keep you on track). Write it yourself, run it, and check your output against the example in the comments. This is exactly the kind of small program you'll build constantly.
🎉 Lesson Complete
- ✅ C# is a modern, versatile language for games, web, desktop, and mobile
- ✅ .NET is the platform that runs C# code on Windows, macOS, and Linux
- ✅ Every program needs using System; , a class , and a Main method
- ✅ Console.WriteLine() prints with a new line; Console.Write() prints without
- ✅ String interpolation: $"Hello {name} " embeds variables in strings
- ✅ C# is strongly typed — every variable has a declared type
- ✅ Statements end with ; and code blocks use {} braces
- ✅ Next lesson: Variables & Data Types — the building blocks of every program
Practice quiz
Which method prints text and then moves to a new line?
- Console.Write()
- Console.WriteLine()
- Console.Print()
- Console.Log()
Answer: Console.WriteLine(). Console.WriteLine() prints the text and then moves the cursor to a new line; Console.Write() stays on the same line.
Which line must be at the top so you can use Console?
- import System;
- using System;
- include System;
- namespace System;
Answer: using System;. Console lives in the System namespace, so you need 'using System;' to access it.
Every C# statement must end with which character?
- A colon :
- A comma ,
- A semicolon ;
- A full stop .
Answer: A semicolon ;. Statements end with a semicolon; forgetting it gives the error 'CS1002: ; expected'.
What is the entry point method where a C# program starts running?
- Start()
- Run()
- Main()
- Begin()
Answer: Main(). Main is the entry point — execution begins there.
Which is the correct string interpolation syntax to embed a variable name?
- "Hello {name}"
- $"Hello {name}"
- f"Hello {name}"
- "Hello " {name}
Answer: $"Hello {name}". Interpolation needs the $ prefix, then variables go inside {curly braces}.
C# is case-sensitive. Which of these works?
- console.writeline()
- Console.Writeline()
- Console.WriteLine()
- CONSOLE.WRITELINE()
Answer: Console.WriteLine(). It must be Console.WriteLine with capital C, W, and L — capitalisation is part of the name.
Which symbols wrap text (a string) in C#?
- 'single quotes'
- "double quotes"
- (parentheses)
Answer: "double quotes". Strings use double quotes; single quotes are only for a single char like 'A'.
What does Console.Write() do differently from Console.WriteLine()?
- It prints to a file instead
- It does not add a new line at the end
- It only prints numbers
- It clears the screen first
Answer: It does not add a new line at the end. Write() leaves the cursor on the same line, so the next output continues right after it.
What does it mean that C# is strongly typed?
- Code must be typed quickly
- Every variable has a declared type that fixes what it can hold
- All variables are text
- Types are optional everywhere
Answer: Every variable has a declared type that fixes what it can hold. Strongly typed means each variable has a specific type (string, int, double, bool, ...) fixing what it can store.
What platform does C# run on, giving it cross-platform support?
- .NET
- JVM
- Node.js
- Ruby on Rails
Answer: .NET. C# runs on the .NET platform, which works on Windows, macOS, and Linux.
Continue this course
- Next: Variables & Data Types