▲ | recursive 4 days ago | |||||||||||||||||||||||||
SomeMethod().Fire(); has the same "problem". var e = new Employee(); does not. The problem you see is independent from var. | ||||||||||||||||||||||||||
▲ | breadwinner 4 days ago | parent [-] | |||||||||||||||||||||||||
You are right, SomeMethod().Fire() has the problem too. But typically you write
This does NOT have the same problem as var. When you use var you reduce the opportunities for the compiler to catch your bug. So the best practice is to explicitly state the type when possible. It makes the code more readable too.What's more, Microsoft recommends using implicit typing for local variables only when the type of the variable is obvious from the right side of the assignment. See: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals... But that's not what the community is doing, and some tools (JetBrains Rider) recommend using var whenever possible. | ||||||||||||||||||||||||||
|