I want to convert a nullable numeric into a string maintaining the null value. This is what I'm doing:
int? i = null;
string s = i == null ? null : i.ToString();
Is there something shorter?
I want to convert a nullable numeric into a string maintaining the null value. This is what I'm doing:
int? i = null;
string s = i == null ? null : i.ToString();
Is there something shorter?
We can also use System.Convert i.e.
int? i = null;
string s = Convert.ToString(i); // it gives null if i is null.
And as already mentioned we can also use null conditional operator
string s = i?.ToString();