Lesson 5: var & naming
When the value already says what the type is, you can write var instead of repeating the type: var name = "Dana"; — C# infers that name is a string. Note: var is still a fixed type (you can't put a number in later). We'll also learn naming rules: a name starts with a letter or _, has no spaces, and
var is a shortcut: 'look at the value and figure out the type yourself'. And a variable's name is like a first name — you must write it exactly the same every time, capital letters included.
- var
- A word that asks C# to infer the type from the value. The type is still fixed.
- case-sensitivity
- C# distinguishes upper and lower case: name and Name are two different names.
- naming rules
- A name starts with a letter or _, has no spaces, and is made of letters, digits or _.
- camelCase
- A convention for variable names: firstName, userAge — first word lowercase, each next word capitalized.