Tsallaka zuwa abun ciki
Justice Tech School

C# Tutorial

A modern language for web, desktop, games and cloud on .NET.

Start learning C#
Getting started4 lessons
  1. 1C# IntroductionC# is a modern, object oriented language from Microsoft that runs on .NET.
  2. 2C# Get StartedInstall the .NET SDK, then create a project with dotnet new console and run it with dotnet.
  3. 3C# SyntaxStatements end with a semicolon and blocks use curly braces.
  4. 4C# CommentsUse // for a single line and /* */ for several lines.
Basics14 lessons
  1. 5C# VariablesA variable has a type and a name.
  2. 6C# Constantsconst creates a value that cannot change after it is declared, and it must be set at compi.
  3. 7C# Data TypesC# has value types such as int, double, bool and char, and reference types such as string,.
  4. 8C# Type CastingWidening conversions are automatic, narrowing needs a cast.
  5. 9C# User InputConsole.ReadLine reads a line of text as a string.
  6. 10C# Output and FormattingConsole.Write prints without a newline.
  7. 11Top Level StatementsModern C# lets a file start directly with statements, with no Main method or class.
  8. 12var, const and readonlyvar infers a local type.
  9. 13Value Typesint, double, bool, char, decimal and struct types hold their value directly.
  10. 14Nullable TypesAdd ? to let a value type hold null.
  11. 15Type ConversionImplicit conversions widen safely, explicit casts narrow and Convert, Parse and TryParse h.
  12. 16Console Input and OutputConsole.WriteLine writes a line, Write does not, and ReadLine reads text.
  13. 17The Math ClassMath has Abs, Max, Min, Pow, Sqrt, Round, Floor, Ceiling and PI.
  14. 18Random NumbersRandom.Shared gives numbers.
Operators9 lessons
  1. 19C# Arithmetic OperatorsUse + - * / and % for the remainder.
  2. 20C# Assignment Operatorsx += 3 means x = x + 3.
  3. 21C# Comparison and Logical OperatorsComparison operators are == != < > <= >=.
  4. 22C# Null Operators?? gives a default when a value is null and ?.
  5. 23Arithmetic Operators+ - * / % work as usual.
  6. 24Comparison and Logical Operators== != < > <= >= compare and && || ! combine booleans.
  7. 25Null Operators?? gives a default, ??= assigns if null and ?.
  8. 26Ternary and Switch Expressionscond ? a : b picks between values.
  9. 27Bitwise Operators& | ^ ~ << >> work on bits.
Strings8 lessons
  1. 28C# StringsStrings are immutable sequences of characters.
  2. 29C# StringBuilder and EscapesJoining many strings in a loop is slow, so use StringBuilder.
  3. 30String BasicsStrings are immutable sequences of characters.
  4. 31String Interpolation and Formatting$"..." embeds expressions.
  5. 32More String MethodsContains, StartsWith, IndexOf, Replace, Trim, Split, Join and PadLeft cover most needs.
  6. 33StringBuilderStringBuilder builds text efficiently in loops.
  7. 34Comparing StringsUse == or Equals.
  8. 35Verbatim and Raw Strings@"..." keeps backslashes and spans lines.
Control flow12 lessons
  1. 36C# If and Elseif runs code when a condition is true.
  2. 37C# Switchswitch matches one value against cases.
  3. 38C# While and Do Whilewhile repeats while a condition is true.
  4. 39C# For Loopsfor has an initialiser, a condition and an update.
  5. 40C# Foreachforeach visits every item in an array or collection without an index.
  6. 41if, else if and elseBranch on a boolean condition.
  7. 42switch Statementsswitch compares one value with several cases.
  8. 43Pattern Matchingis, switch and property patterns test shape and type in one step.
  9. 44for and while Loopsfor has init, condition and step.
  10. 45foreachforeach visits each item of a collection.
  11. 46break, continue and gotobreak leaves a loop and continue skips to the next round.
  12. 47Ranges and Indices^1 is the last item and a..b slices.
Arrays and collections13 lessons
  1. 48C# ArraysAn array holds a fixed number of values of one type.
  2. 49C# ListsList<T> is a resizable list.
  3. 50C# DictionariesDictionary<K,V> stores key value pairs with fast lookup by key.
  4. 51C# LINQ BasicsLINQ queries collections with Where, Select, OrderBy, Sum, Count and more.
  5. 52ArraysArrays have a fixed size and zero based index.
  6. 53List<T>List<T> grows automatically.
  7. 54DictionaryDictionary<K, V> stores key value pairs.
  8. 55HashSet and Queue and StackHashSet keeps unique items.
  9. 56LINQ BasicsLINQ queries collections with Where, Select, OrderBy, First, Any and Count.
  10. 57LINQ GroupBy, Join and AggregatesGroupBy buckets items, Sum, Average, Min and Max aggregate.
  11. 58Tuples and DeconstructionTuples group values without a class.
  12. 59Collection Initialisers and SpreadInitialise collections inline.
  13. 60Custom SortingOrderBy, ThenBy and Comparer control sort order.
Methods9 lessons
  1. 61C# MethodsA method is a reusable block of code.
  2. 62C# ParametersParameters can have default values, be passed by name, and use ref or out to change the ca.
  3. 63C# Recursion and LambdasA method can call itself with a base case.
  4. 64MethodsA method has an access level, return type, name and parameters.
  5. 65Optional and Named ArgumentsGive parameters defaults and call them by name.
  6. 66params, ref and outparams takes any number of arguments, ref passes by reference and out returns extra values.
  7. 67Method OverloadingSeveral methods may share a name with different parameters.
  8. 68Local Functions and LambdasFunctions can live inside methods.
  9. 69RecursionA method may call itself.
Object oriented C#19 lessons
  1. 70C# Classes and ObjectsA class is a blueprint and an object is an instance made with new.
  2. 71C# ConstructorsA constructor runs when an object is created and sets up its fields.
  3. 72C# PropertiesProperties wrap fields with get and set accessors.
  4. 73C# InheritanceA class can inherit from one base class with a colon.
  5. 74C# Interfaces and Abstract ClassesAn interface lists members a class must provide, and a class can implement many.
  6. 75C# Static Membersstatic members belong to the class, not to objects.
  7. 76C# Enums, Structs and RecordsAn enum names a set of constants.
  8. 77Classes and ObjectsA class has fields, properties, a constructor and methods.
  9. 78PropertiesProperties wrap fields with get and set.
  10. 79Access Modifierspublic, private, protected, internal and protected internal control visibility.
  11. 80InheritanceA class extends another with a colon.
  12. 81InterfacesAn interface lists members a class must implement.
  13. 82abstract and sealedabstract classes cannot be created and may require members.
  14. 83static Membersstatic members belong to the type, not to objects.
  15. 84Recordsrecord gives value equality, ToString and with expressions for immutable data.
  16. 85EnumsAn enum names a set of integer constants.
  17. 86GenericsGeneric classes and methods work with any type, with constraints.
  18. 87Extension MethodsA static method with this on the first parameter adds a method to an existing type.
  19. 88ToString, Equals and GetHashCodeOverride ToString for text and Equals with GetHashCode for value comparison.
Errors and files13 lessons
  1. 89C# Exceptionstry runs risky code, catch handles an error and finally always runs.
  2. 90C# FilesThe File class reads and writes files.
  3. 91try, catch and finallyHandle errors with try and catch.
  4. 92throw and Custom Exceptionsthrow raises an exception.
  5. 93using and IDisposableusing disposes a resource when the block ends, even after an error.
  6. 94Files with File and PathFile.WriteAllText, ReadAllText and ReadAllLines handle small files.
  7. 95JSON with System.Text.JsonJsonSerializer converts objects to JSON and back.
  8. 96Dates and TimesDateTime, TimeSpan and DateOnly handle dates.
  9. 97async and awaitasync methods return Task.
  10. 98Nullable Reference TypesWith nullable enabled the compiler warns about null.
  11. 99Practice: Word FrequencySplit text and count with a dictionary or LINQ.
  12. 100Practice: FizzBuzzCombine a loop with a switch expression.
  13. 101Practice: Bank AccountCombine class, property and exception.
Advanced C#Premium7 lessons
  1. 102C# GenericsGenerics let a class or method work with any type while staying type safe.
  2. 103C# Delegates and EventsA delegate is a type that holds a method reference.
  3. 104C# Async and Awaitasync methods return Task and use await so the thread is free while waiting for slow work .
  4. 105C# Advanced LINQGroupBy, OrderByDescending, ThenBy, Join, Any, All, First, ToDictionary and Aggregate expr.
  5. 106C# Pattern Matchingis and switch can test types, properties and ranges in one step.
  6. 107C# Nullable Reference TypesWith nullable reference types enabled, string cannot be null and string? can.
  7. 108C# Dependency InjectionPass the things a class needs through its constructor instead of creating them inside.
C# in practicePremium6 lessons
  1. 109ASP.NET Core Minimal APIASP.NET Core is the web framework for .NET.
  2. 110Entity Framework CoreEF Core maps C# classes to database tables so you query with LINQ instead of SQL.
  3. 111Unit Testing with xUnitxUnit is a popular test framework.
  4. 112Clean Code and Design PatternsKeep classes small with one job, depend on interfaces, avoid duplicated code and name thin.
  5. 113Memory and PerformanceThe garbage collector frees unused objects.
  6. 114Packages, Projects and PublishingNuGet is the package manager: dotnet add package Name.
Next steps1 lessons
  1. 115What Next?Practise by building: a console game, a REST API with EF Core, then a Blazor or MAUI app.