Friday, June 18, 2010

Is there a benefit to storing an object in a variable before calling a method on it?

Programmer Question

Example 1:



SomeObject someObject = new SomeObject();
if (someObject.Method())
{
//do stuff
}
//someObject is never used again


vs



Example 2:



if (new SomeObject().Method())
{
//do stuff
}


Is there any benefit to using the first method over the second, or vice versa?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails