FREE COURSE | BEGINNER

C# Programming Fundamentals

Build programming skills for .NET applications and future Unity projects.

Learning objectives

Run console programs, use types and control flow, process arrays, and model game players using classes and methods.

Prerequisites: basic computer skills. Install a supported .NET SDK, such as .NET 10.

01. Introduction to C# and .NET

C# is a statically typed language. .NET provides a runtime and libraries. C# is used for web, desktop and game development. Unity uses its own supported C# environment.

C# source code

Expected output (original example)

Hello, C#!

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Change the greeting.

02. Installation and Program Structure

Install the .NET SDK from dotnet.microsoft.com. Check dotnet --version. Run dotnet new console -n LearningLab, then cd LearningLab. Replace Program.cs with each complete example and run dotnet run. Main is the conventional entry point; braces define blocks.

C# source code

Expected output (original example)

My first program

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Remove a semicolon, observe the error, and restore it.

03. Variables, Data Types and Input/Output

int stores integers, double stores floating-point values, bool stores true or false, and string stores text. Console.ReadLine reads input; TryParse safely converts text to a number. This example uses sample input.

C# source code

Expected output (original example)

Ana: 85

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Replace the sample input with Console.ReadLine() and test invalid input.

04. Operators and Expressions

Arithmetic uses +, -, *, / and %. Integer division truncates toward zero. Comparisons produce bool values; && and || combine conditions.

C# source code

Expected output (original example)

3
1
True

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Change b to 3 and predict the output.

05. Conditional Statements

Use if, else if and else to select a branch. Test boundary values to verify the logic.

C# source code

Expected output (original example)

Passed

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Test 90, 75 and 74.

06. Loops and Arrays

Arrays store fixed-length sequences of one type with zero-based indexes. for and while repeat instructions; foreach visits each element.

C# source code

Expected output (original example)

10

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Add another value to the array.

07. Methods, Classes and Objects

Methods group reusable behavior. A class defines data and behavior; new creates an object. Constructors initialize fields and private setters restrict changes.

C# source code

Expected output (original example)

Ana: 30 XP

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Create a second player and collect more coins.

08. Interactive C# Practice Lab

Trace a for loop that adds integers to a running total. The browser simulator models the original loop, not arbitrary edited C# code.

C# source code

Expected output (original example)

15

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Loop simulator

Sum: 15

JavaScript simulation, not a C# compiler.

Try it yourself

Predict the sum for ten iterations.

09. Mini Project: Game Player System

Combine objects, arrays and methods to build a console game score prototype. Each coin earns ten XP. This is a console application, not a Unity scene.

C# source code

Expected output (original example)

Ana: 50 XP
Ben: 30 XP

Reference output for the original example. Replace Program.cs and run dotnet run locally to test edits.

Try it yourself

Add a third player and implement a level-up rule.

10. Knowledge Check

Continue with C# for Game Development.