IAdapter IAdapter - 1 year ago 79
C# Question

Why should I use var instead of a type?

Possible Duplicate:

ReSharper and var

After I have installed ReShaper it demands(by warnings) that I use var whenever possible, for example

UnhandledExceptionEventArgs ue = (UnhandledExceptionEventArgs) t;

ReSharper wants to turn it into

var ue = (UnhandledExceptionEventArgs) t;

I like the first version better, is there any reason to prefer var? better performance? anything? or is it just a code style?

Answer Source

It's really just a coding style. The compiler generates the exact same for both variants.

See also here for the performance question:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download