Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Local variables in .Net

I just want to know that creating local variables to accept the return value of function is going to hit memory usage or performance in .Net applications , especially in ASP.Net.

say

 MyObject myObject = Foo();
 MyOtherObject myOtherObject = Boo();

 SomeFuntion(myObject, myOtherObject);

OR

Should I use

 MyFunction(Foo(), Boo());

Certainly the former usage has a better readability.. But what about the memory usage and performance?

Thanks in advance 123Developer

like image 645
123Developer Avatar asked Nov 30 '22 07:11

123Developer


1 Answers

Don't optimise prematurely; in a release build it is quite likely that the compiler will optimise these away anyway! Either way, you are just talking a tiny amount of stack space for (presumably) a few references. Either approach is fine; go with whichever is more readable.

like image 113
Marc Gravell Avatar answered Dec 05 '22 06:12

Marc Gravell