How to convert nullable int to string

c#

Solution

You can simply use the `Convert.ToString()` which handles the null values as well and doesn't throw the exception

string str = Convert.ToString(a)

Or using `if` condition

if(a.HasValue)
{
  string str = a.Value.ToString();
}

Or using `?` Ternary operator

string str = a.HasValue ? a.Value.ToString() : string.Empty;

Problem

I need to convert the nullable int to string ``` int? a = null; string str = a.ToString(); ``` How can I perform this action without an exception? I need to get the string as "Null". Please guide me.

Original source

Related problems