I\'d like to have an integer variable which can be set to null and don\'t want to have to use the int? myVariable
syntax. I tried using int
and
Yes you should use nullable types
See Nullable
Nullable<int> Nullable<float>
or simply
int? float?
PS:
If you don't want to use ? notation or Nullable at all - simply use special structures for such a thing. For example DataTable:
var table = new DataTable();
table.Columns.Add('intCol',typeof(int));
var row = table.NewRow();
row['intCol'] = null; //
Yes. That's why Microsoft added that. People were creating their own Nullable class so they included this pattern in .NET.