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 all programming languages, but are particularly important in C#. That’s because C# is known as a strongly-typed language—it requires that the programmer specify the data type of every value and expression. While it means writing more code, using types has long term benefits like built-in documentation and increased readability.
As we can see to the diagram to the right, C# has several built-in data types. You don’t need to memorize all of them, but pay specific attention to these common ones that we’ll use throughout our lessons:
int
- whole numbers, like: 1, -56, 948double
- decimal numbers, like: 239.43909, -660.01char
- single characters, like: “a”, “&”, “£”string
- string of characters, like: “dog”, “hello world”bool
- boolean values, like: true or false
Instructions
Review the diagram to the right to see the difference between different C# data types and their usage. Continue when you’re ready.