Programming foundations

Stage 1 · Lesson 5 of 9

Methods, classes and properties

Your first language

group data (fields) and behaviour (), and new Book("Dune", 412) runs a class's constructor, the setup code for a new object. Methods have a return type and typed parameters, such as static decimal Total(List<decimal> items), and void means they return nothing.

Arguments are passed by value, meaning the method gets a copy. For a number, that is a copy of the number. For an object, it is a copy of the reference, so a method can add to a List you pass in but cannot replace your variable.

The keywords ref and out change that, and are used sparingly. C# uses , such as public string Title { get; private set; }, instead of separate methods. Callers read book.Title, while the class controls changes.

, such as record Point(int X, int Y);, give you a data type that cannot change, in one line.

A question to check yourself, an AI practice session and 4 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • GuideFree
    Learn C#

    Microsoft · Beginner

    Official C# fundamentals tutorials that you run locally with the .NET SDK

  • PlatformFree
    freeCodeCamp

    freeCodeCamp · Beginner

    Free Foundational C# certification, built with Microsoft, with a graded exam at the end

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • Quick C# syntax lookups with a try-it editor; not a replacement for the course

Mark this stage as not done?