Um momento
0x10Lesson 2 of 6

Use types, input, and strings

Store typed values, read console input, and format output.

15 min 5-question quiz
By the end of this lesson you can
  • Use common C# types, Console.ReadLine, parsing, and interpolation.

C# checks types at compile time. int stores whole numbers, double stores floating-point numbers, bool stores true or false, and string represents text. var asks the compiler to infer a local variable type from its initializer; it does not make the variable dynamically typed. Console.ReadLine returns text, so numeric input must be parsed, for example with int.Parse.

Program.cs · C# 12
1using System;
2
3class Program
4{
5    static void Main()
6    {
7        string name = Console.ReadLine() ?? "friend";
8        Console.WriteLine($"Welcome, {name}!");
9    }
10}
Output
Input: Riley
Welcome, Riley!

The ?? operator provides a fallback if the left side is null. C# nullable reference types add compile-time warnings about possible null values when enabled; they help communicate intent but do not add runtime null checks automatically.

Key takeaways

  • C# is statically typed, including locals declared with var.

  • Console input arrives as text and needs parsing for numbers.

  • Use interpolation to format values into strings.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: