11,576 questions
Try...
new KeyValuePair<string, string>("latitude", latitude.HasValue ? latitude.Value.ToString() : "")
Reference documentation.
?: operator (C# reference)
Nullable value types (C# reference)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have the following in my app:
double? latitude;
..................
..................
..................
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("latitude", latitude),
}
How can I check for the vale of latitude so if it's null then pass "" otherwise pass Convert.ToString(latitude)?
Thanks,
Jassim
Try...
new KeyValuePair<string, string>("latitude", latitude.HasValue ? latitude.Value.ToString() : "")
Reference documentation.
?: operator (C# reference)
Nullable value types (C# reference)
You could do something like this:
double? latitude = null;
// ...
Console.WriteLine(latitude?.ToString() ?? "");