C# TutorialLesson 7Free preview
C# Variables
This lesson is part of C# · All levels
Summary
A variable is a named container for storing data of a certain type, for example int age = 20. The name of the variable must not be preceded by a number, must not contain spaces, and must not be the same as the C# keyword. In addition there is const for fixed values and var for short writing thanks to type inference.
Key points
- The declaration of a variable is a type of value name, and the type must correspond to the stored value.
- The name of the variable must not be preceded by a number and must not be a C# keyword.
- Keyword const makes a constant that cannot be changed after declaration.
- Keyword var only abbreviates the writing; the actual type remains inferred from the initial value.
- Variables must be assigned a value before use to avoid the error of the unassigned local variable.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.