Both are compiled to the same MSIL code. The only difference is a possible convenience for you while writing source code - if you decide to change the type of p
later on, you only have to replace Person
once in the constructor call and you can leave the variable declaration intact when using var
.
That said, var
goes along with a slight decrease in legibility, as you cannot see the type of p
instantly any more at the beginning of your line. Therefore, restrict your use of var
to occasions where it really saves some typing, such as for complicated nested generic types.
Note that, if you do not initialize your variable right away (in the same statement where the variable is declared), you cannot use var
as the compiler cannot infer the type of the variable.