Why does ReSharper want to use 'var' for everything?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
ReSharper does not actually want var for everything by default because var is universally superior. It suggests var based on a configurable style rule that assumes local code is often easier to read when the right-hand side already makes the type obvious.
What var Really Means in C#
var is not dynamic typing. The compiler still infers one static type at compile time.
After compilation, each variable has a concrete type exactly as if you had written it explicitly. So the ReSharper suggestion is a style preference, not a semantic rewrite of the language.
Why Tools Prefer var in Obvious Cases
When the type is already clear from the expression, repeating it can add noise without adding information.
Many teams prefer:
In this case the constructor already tells you the type. ReSharper often treats that as the cleaner option because the line emphasizes the variable name and intent rather than duplicating the type.
This is especially common with:
- '
new SomeType(...)' - LINQ projections
- long generic types
- anonymous types where explicit typing is impossible anyway
Why Some Developers Disagree
The argument against var is usually about readability in less obvious code.
Without more context, result could be many things. Some teams prefer:
That makes the type visible at the point of use. ReSharper can be configured to respect this preference too. The point is not that one style is objectively correct in every case, but that a codebase should choose a rule that makes review and maintenance consistent.
ReSharper Uses Configurable Inspection Rules
ReSharper has code style settings for implicit versus explicit typing. You can tell it to:
- use
vareverywhere - use
varonly when the type is evident - prefer explicit types in ambiguous cases
That means the suggestion you see reflects the team's or local profile's settings, not a hard language requirement.
A common compromise is:
- '
varfor obvious constructor calls' - '
varfor anonymous types and LINQ' - explicit types when the right-hand side hides the real type
That policy aligns with how many experienced C# teams write local variables.
Readability Depends More on Naming Than on var
People often focus on the keyword and ignore the larger issue: a vague variable name can make code unclear regardless of whether the type is explicit.
is worse than:
Clear names, small methods, and obvious expressions usually matter more than whether the local variable uses var or an explicit type.
Common Pitfalls
- Assuming
varmeans runtime dynamic typing in normal C# code. - Treating ReSharper suggestions as language rules rather than configurable style settings.
- Using
varwhen the right-hand side hides the type and hurts readability. - Banning
varcompletely and creating repetitive noise in obvious constructor calls. - Debating the keyword endlessly instead of agreeing on a consistent team style.
Summary
- ReSharper suggests
varbecause many code style profiles prefer implicit typing when the type is obvious. - '
varstill produces a concrete compile-time type.' - The real tradeoff is readability, not correctness.
- ReSharper can be configured to prefer explicit types where they add clarity.
- Consistency across the codebase matters more than winning a style argument on one line.
Related reading
- Why does StyleCop recommend prefixing method or property calls with this?
- Why does System.Net.Sockets.Socket.AcceptAsync complete with ConnectionReset after a long time of inactivity?
- Why does the compiler only allow a generic returned task if I async/await it?
- Why does visual studio 2012 not find my tests?
- Why doesn't an async LINQ Select lambda require a return value
- Why doesn't Any work on a c null object
- Why doesn't await on Task.WhenAll throw an AggregateException?
- Why doesn't await on Task.WhenAll throw an AggregateException?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.