Monday, April 13, 2009

var title=???

Initially when I started using the var keyword in C# I was very cautious about it. I felt it impacts the readability of the code and decided that I will use it only with anonymous types.

But nowadays I use it whenever I directly assign a value to it but if the value is something that is assigned from a function call or from a collection then I still prefer to specify the actual type (unless of course the collection contains elements of an anonymous type). So for me “var x = 10” is fine but “var x = Something()” is not. Would be interesting to find out what guidelines others have when it comes to the var keyword.