Are parameters evaluated in order when passed into a method?

后端 未结 3 1419
春和景丽
春和景丽 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:47

    Yes, expressions passed as arguments to methods are always evaluated from left to right.

    From the C# 4.0 Language Specification:

    7.5.1.2 Run-time evaluation of argument lists

    During the run-time processing of a function member invocation (§7.5.4), the expressions or variable references of an argument list are evaluated in order, from left to right, [...]

提交回复
热议问题