C# Basics
These four tutorials cover the parts of C# that every other feature builds on. Each one is a hands-on page with compiled samples from one invented online shop, OrdersPortal, a complete working program at the end, and a table of the real compiler errors beginners hit. Read them in order: each page assumes the ones before it. If you already know another object-oriented language, skim the first two and slow down where C# differs: value versus reference types, properties, switch without fall-through, and interfaces.
What this section covers
Section titled βWhat this section coversβ- Data: built-in types,
var, value versus reference types, operators, arrays, namespaces andusingdirectives. - Behavior:
if,switch, loops, methods and their parameter kinds, and exceptions. - Object-oriented programming: classes, properties, constructors, access modifiers, static members, inheritance, abstract classes, interfaces and polymorphism.
You need the .NET 10 SDK (or later) and a terminal. The samples were compiled with .NET SDK 10.0.115.
Learning path
Section titled βLearning pathβ- Types, variables and operators: declare typed variables, use arithmetic, comparison, logical and null operators, store values in arrays, and organize code with namespaces and
usingdirectives. You build an order-total calculator. - Control flow and methods: branch with
ifandswitch, repeat with loops, write methods with default, named,params,outandrefparameters, and handle errors withtry,catchandfinally. You build a checkout that validates and prices order lines. - Classes and objects: define classes with properties and methods, write and chain constructors, protect state with access modifiers, and share data with static members. You build a shopping cart.
- Inheritance and interfaces: derive classes with
baseandoverride, share an algorithm with abstract classes, define contracts with interfaces, and let polymorphism choose the method at run time. You build an order processor with pluggable payment methods and notifiers.
Map of topics
Section titled βMap of topicsβEvery basics topic has its own section on one of the four pages.
| Topic | Section |
|---|---|
| Variables and data types | Types, variables and operators: variables |
| Operators | Types, variables and operators: operators |
| Arrays | Types, variables and operators: arrays |
| Namespaces | Types, variables and operators: namespaces |
| Using directives | Types, variables and operators: using directives |
Control flow (if, switch, loops) |
Control flow and methods: control flow |
| Methods and parameters | Control flow and methods: methods |
| Exception handling | Control flow and methods: exceptions |
| Classes and objects | Classes and objects |
| Constructors | Classes and objects: constructors |
| Access modifiers | Classes and objects: access modifiers |
| Static members | Classes and objects: static members |
| Inheritance | Inheritance and interfaces: inheritance |
| Abstract classes | Inheritance and interfaces: abstract classes |
| Interfaces | Inheritance and interfaces: interfaces |
| Polymorphism | Inheritance and interfaces: polymorphism |
Where to go next
Section titled βWhere to go nextβ- C# topic hubs: twelve topic pages that group the language features by the problem they solve, in a suggested learning order. Start with types and records and null handling.
- C# versions: what each C# release added, with full release guides for C# 5 and C# 12 onward.
- C# interview questions: test your understanding.