We have "use var when evident" set on everything, since I prefer to use "var" when I can look at the line of code and immediately determine what the type will be. If you new it up on that line, it's obvious what it will be. If you cast is using an explicit conversion or with an "as", it's obvious what it will be. However, one behavior that I'm a bit confused by is this one:
public void Test()
var i = GetGeneric<int>();
public T GetGeneric<T>()
It appears that reSharper believes the type of "i" would be evident since GetGeneric returns a type T, which we specify as an int when we call the method. However, this would not be evident to someone who cannot see the implementation of the method. That type parameter might be used for something else or not even used at all.
From what I can tell, this is not a reSharper bug but a well thought-out design and quite purposeful. For example, if I change the return type of GetGeneric to anything but T, reSharper will suggest I get rid of the var. If I have more than one type parameter on GetGeneric, same thing. So, one could argue that the fact I don't see a warning tells me that this method will return an int, but I would have to be well aware of reSharper behavior and my current configuration to know that.
In my opinion, the type is not "evident" and thus reSharper should not treat this as such. I'm curious on other opinions, or perhaps the thought process behind this design decision. Thanks!