Closed
Description
public class C {
public int A(int i) {
i += 2;
i += 4;
return i;
}
public int B(int i) {
var j = i;
j += 2;
j += 4;
return j;
}
public int ConsumeA(int i) => A(i);
public int ConsumeB(int i) => B(i);
}
According to @SingleAccretion, this is because Roslyn prefers to use the IL stack for locals instead of parameters.
So an optimization would make sense for this.
I would argue that there is a real-world case, as I have seen code where no new variable was created but the parameter was modified directly.