I'm currently learning functional programming, and I was wondering if there is a difference between these functions.
Func<int, int> incrementByOne = x => x += 1;
Func<int, int> incrementByOne2 = x => x + 1;
Run Code Online (Sandbox Code Playgroud)
There is no difference. Because:
int is a value type, so passed by value (being copied), thus in x => x += 1 changing x cannot affect the source (no side effects)+= returns the result of addition, so the same as + does| 归档时间: |
|
| 查看次数: |
96 次 |
| 最近记录: |