The “var” keyword in C# is used to declare implicitly-typed variables. This means that the type of the variable is determined by the compiler, based on the expression used to initialize the variable.
The main benefit of using “var” is to reduce code verbosity and make the code easier to read.
It’s worth noting that the type of a var
variable must be determined at compile-time, so you can’t use var
with anonymous types or with types that are only known at runtime. However, var
can be used with any other type, including custom types, built-in types, arrays, and more.