Key Concepts

Review core concepts you need to learn to master this subject

Variables and Types

string foo = "Hello"; string bar = "How are you?"; int x = 5; Console.WriteLine(foo); // Prints: Hello

A variable is a way to store data in the computer’s memory to be used later in the program. C# is a type-safe language, meaning that when variables are declared it is necessary to define their data type.

Declaring the types of variables allows the compiler to stop the program from being run when variables are used incorrectly, i.e, an int being used when a string is needed or vice versa.

Data Types and Variables
Lesson 1 of 3
  1. 1
    When we write programs, we’re telling the computer how to process pieces of information, like the numbers in a calculation, or printing text to the screen. So how does a computer distinguish betwee…
  2. 2
    Data types tell us a few things about a piece of data, like: - How it can be stored - What operations we can perform with it - Different methods it can be used with Data types are present in al…
  3. 3
    When we use data in our programs, it’s good practice to save them in a variable. A variable is basically like a box in our computer memory where we can store values used in our code. In C#, data…
  4. 4
    When you program, you’ll come across a lot of errors. And that’s ok! And when you’re first starting to learn a strongly-typed language, they can be pretty common. So, what happens if you forget t…
  5. 5
    Because variables have to be strictly typed, there may be some circumstances where we want to change the type of data a variable is storing. This strategy is known as data type conversion. For …
  6. 6
    Congratulations! In this lesson, you learned about how data types and variables work in C#. Topics covered include: - C# built-in data types, including int, double, char, string, and bool - How to…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo