I have been looking through some code on an open source project recently and found many occurrences of this kind of code:
class SomeClass
{
private int SomeNumber = 42;
public ReturnValue UseSomeNumber(...)
{
int someNumberCopy = this.SomeNumber;
if (someNumberCopy > ...)
{
// ... do some work with someNumberCopy
}
else
{
// ... do something else with someNumberCopy
}
}
}
Is there any real benefit to making a copy of the instance variable?