Does var compile to the same code?
In a code review the other day the topic of when to use var and when to use a non-inferreddata-type. That’s a religious argument and probably a post for another day but the question of
Is there any difference between the code produced using var and using, say, string?
I confidently answered “No, it is identical. The type is inferred by the compiler and replaced”. But I was thinking about it later and I wondered if I was right.
I created a really simple test program
This code compiled down to
Changing the string to var produced exactly the same IL. So, oddly, I was right about something.