Are parameters evaluated in order when passed into a method?

后端 未结 3 1417
春和景丽
春和景丽 2020-12-11 00:03

Are parameters evaluated in order when they passed into a method?

For Java it\'s always true, for C it isn\'t, but what is the answer for C#?

Sample

3条回答
  •  执笔经年
    2020-12-11 00:43

    As others have pointed out, the language specification requires that parameters be evaluated in left-to-right order.

    However, full disclosure, we accidentally and not on purpose introduced a couple of bugs in C# 4.0 where certain scenarios involving named arguments, optional parameters and ref-omitted parameters in calls to legacy COM objects, such that in those scenarios the side effects of arguments might not be evaluated in strictly left-to-right order. The analyzer that deals with the interactions between those features is complicated and it had some bugs.

    I apologize for the errors; we hope to have them fixed in the next version.

提交回复
热议问题