A long time ago in a galaxy var, var away…

baby-in-front-of-computer1-150x150_0I, like many other C# developers use the var keyword. But why are we using it so much when we know the type that our var will become?

The rule that  I and many other developers follow is that it is OK to use var as long as the incoming type is easily discovered by looking to the right of your assignment operator.

var form = new Form(); [good]

var formId = SaveForm(); [bad] what the heck does SaveForm return? A good guess would be an int but what if it’s a GUID or a string?

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.