C # code will not compile. There is no implicit conversion between zero and int

Possible duplicate:
Zero types and ternary operator: why? 10: null` is forbidden?

Why is this not working? Looks like a valid code.

string cert = ddCovCert.SelectedValue; int? x = (string.IsNullOrEmpty(cert)) ? null: int.Parse(cert); Display(x); 

How do I encode this? The method is Nullable. If a row is selected in the drop-down list, I need to parse this into int, otherwise I want to pass null to the method.

+55
string null c # nullable
Aug 14 '09 at 17:16
source share
2 answers
 int? x = string.IsNullOrEmpty(cert) ? (int?)null : int.Parse(cert); 
+190
Aug 14 '09 at 17:18
source share

I came across the same ... I usually just passed null to (int?)

 int? x = (string.IsNullOrEmpty(cert)) ? (int?)null: int.Parse(cert); 
+7
Aug 14 '09 at 17:19
source share



All Articles