nullable var using implicit typing in c#?

user37468 picture user37468 · Feb 11, 2009 · Viewed 9.2k times · Source

Is there anyway to have the var be of a nullable type?

This implicitly types i as an int, but what if I want a nullable int?

var i = 0;

Why not support this:

var? i = 0;

Answer

Andrew Hare picture Andrew Hare · Feb 11, 2009

var is typed implicitly by the expression or constant on the right hand side of the assignment. var in and of itself is not a type so Nullable<var> is not possible.