Possible Duplicate:
Are parameters evaluated in order when passed into a method?
Say I have
void foo (int x, int y)
and call it by:
foo(y: genNum(), x: genNum())
Does C# guarantee the evaluation order of x and y in this case?
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.
According to the specification, arguments are always evaluated from left to right. Unfortunately, there are a few bugs in some corner cases in C# 4.0. See Eric Lippert’s post at Are parameters evaluated in order when passed into a method? for more details.
As an aside, this is probably bad practice. If you want to guarantee the order that the arguments are evaluated, capture the result in a local variable first and then pass the results to the consuming method like:
I can’t think of a good reason to not do it that way.