P
proxyuser
In Troelsen's Pro C# 2008 book, it says
It is permissible... to assign an inferred local variable to null after its
initial assignment (provided it is a reference type):
// OK, is SportsCar is a reference type!
var myCar = new SportsCar();
myCar = null;
....it is illegal to define a nullable implicitly typed local variable using
the C# ? token
// Nope, can't define nullable implicit variables,
// as implicit variables can never be initially assigned
// null to begin with!
var? nope = new SportsCar();
The reason he gives can't be a good reason. Why does it need to be
assignable to null at declaration time to be nullable in general? I don't
see why they couldn't allow
var? n = 0;
n = null;
It is permissible... to assign an inferred local variable to null after its
initial assignment (provided it is a reference type):
// OK, is SportsCar is a reference type!
var myCar = new SportsCar();
myCar = null;
....it is illegal to define a nullable implicitly typed local variable using
the C# ? token
// Nope, can't define nullable implicit variables,
// as implicit variables can never be initially assigned
// null to begin with!
var? nope = new SportsCar();
The reason he gives can't be a good reason. Why does it need to be
assignable to null at declaration time to be nullable in general? I don't
see why they couldn't allow
var? n = 0;
n = null;