Choosing the right data type for a value
Every value in a C# program has a type. The type decides what the value can hold and what you can do with it.
The types you will use daily
| Type | Holds | Example |
|---|---|---|
| int | Whole numbers | 42 |
| double | Numbers with a decimal part | 3.14 |
| bool | True or false | true |
| char | A single character | 'A' |
| string | Text of any length | "hello" |
| DateTime | A date and time | a moment |
How to choose
Ask what the value represents, not what it looks like. An age is a whole number, so use int. A price is money, so consider a decimal type rather than a double. A name is text, so use string. Choosing by meaning keeps you out of trouble later.
Declare with intent. Name the variable for what it holds. A variable called count is clear. A variable called x is a future mystery.
Try it yourself in the data types lab, then continue to blocks of code and the semicolon.