Why visual studio give me an error with :
public void afunction(int? bar){ somecode }
afunction(String.IsNullOrEmpty(Request["foo"])?null:int.Parse(Request["foo"]));
it give me there no implcit conversion between null and int
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The 2nd and 3rd operands for the ? operator must have compatible types. They don’t in your case, the 2nd is null, the 3rd is int. There is no implicit conversion from int to null nor from null to int. Only explicit ones, like a cast to object or
Nullable<int>. You might consider using this:No problem here since there is an implicit conversion from int to int?