Data Types and Variables
Learn about how types and variables are used in C#
StartKey Concepts
Review core concepts you need to learn to master this subject
Variables and Types
Math.Sqrt()
Arithmetic Operators
Unary Operator
Math.Pow()
.toUpper() in C#
IndexOf() in C#
Bracket Notation
Variables and Types
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.
- 1When 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…
- 2Data 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…
- 3When 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…
- 4When 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…
- 5Because 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 …
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory