CPath = (CPath == null) ? Request.Path : CPath;
First of all I wish CLR would just let me do the ? Request.Path and not bother me with creating a :
But I’m asking will it optimize it away? Or still assign.
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.
Well, I would personally write that as:
to make it clearer. An alternative (as mentioned elsewhere) is
But why do you care if there’s an extra assignment? Do you really think that’s going to be a significant performance hit?
Note that if
CPathis a field rather than a local variable, it could potentially make a difference – because the value ofCPathcould change between the first check and the second evaluation, and again between the evaluation and the assignment. Whether that will be noticed depends on caching etc, but it’s not as simple as it might look at first.