Is it faster to make a comparison or a cast in C#.Net?
For example:
bool? flag = null;
...
if(flag == true)... or if((bool)flag)...
Also, what is the cost (in memory) of a cast?
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.
If memory serves the compiler will force you to cast the
bool?to aboolbefore using it in the if statement. You might like the null coalesce operator: