Types are complicated, and the only way to get comfortable with them is by using them. However, here are some important things to keep in mind:
- All variables need to have a specified type (be it explicit or inferred).
- Variables can only hold values of their assigned type (string can't be assigned to int).
- Each type has a set of operations that it can and can't apply (bool can't be subtracted from another value).
- If a variable needs to be assigned or combined with a variable of a different type, a conversion needs to take place (either implicit or explicit).
- The C# compiler can infer a variable's type from its value using the var keyword, but should only be used when the type isn't known when it's created.
That's a lot of nitty-gritty detail we've just jammed into a few sections, but we're not done yet. We still need to understand how naming conventions work in C#, as well as where the variables live in our scripts.