var
The C# keyword that asks the compiler to infer a local variable's type from its initial value and then fix it there.
In more detail
var is not dynamic typing: var sku = "wid-7"; makes sku a string forever, and assigning a number later will not compile. Use it when the type is obvious from the right-hand side.
Example
var sku = "wid-7"; // sku is a stringRelated terms
- static typing — A language rule that every variable has one fixed type, known when the program is compiled, so type mistakes are caught before it runs.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices