Programming foundations

Stage 1 · Lesson 2 of 9

Types, variables and input

Your first language

C# is . The you will use most are int, double, decimal, bool, char and string. var lets the compiler work out a local variable's type for you, and that type is then fixed.

Use decimal for money, because double cannot store 0.1 exactly. cuts off the decimal part, so 7 / 2 is 3. Every type is one of two kinds.

(numbers, bool, structs) are copied when you assign them. Reference types (string, classes, arrays) are shared: assignment copies a reference to the same object. Read with Console.ReadLine(), which returns a string.

Convert it with int.TryParse(input, out int n), which returns false on bad input instead of throwing an error like int.Parse does.

A question to check yourself, an AI practice session and 3 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?