Simple question (I think): Which of these pieces of code would execute faster in C#?
newSpeed = newSpeed > maxSpeed ? maxSpeed : newSpeed;
or
if (newSpeed > maxSpeed)
{
newSpeed = maxSpeed;
}
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.
I am guessing the second would be faster, in some cases, as it does not always do an assignment, whereas the first always does an assignment.
E.g., when
newSpeed <= maxSpeed, no assignment is done, only a comparison.