Monthly Archives: May 2010

Bangers and mash

WHAT 75 of us had for dinner in a 5-star Marriotts a couple of years ago during a company retreat week-end. Testament to the awesomeness of bangers and mash? Or, a meal unfit for the venue?

food*

Eddy.

Declaring variables inside-versus-outside loops

IN .NET, there is no difference between declaring variables inside loops and declaring variables outside loops. Here is the proof.

Here are two programs inside.cs and outside.cs, appropriately named to reflect the two ways respectively.

inside.cs versus outside.cs

And, here is the ILASM obtained by disassembling inside.exe and outside.exe.

ildasm output of inside.exe and outside.exe

As you can see, the two are the same.

So, please leave those variables inside loops when they are not needed outside. Having the variables closer to their point of use makes the code easier to read.

Eddy.