Without the var keyword it becomes possible to accidentally create a new variable when you had actually intended to use an already existing variable. e.g.
name = "fred";
...
Name = "barney"; // whoops! we meant to reuse name
More Related Contents:
- C# – variable not setting from another class
- What’s wrong with my C# codes?
- C# – How to convert variables? (String, int, etc.) [duplicate]
- What’s the use/meaning of the @ character in variable names in C#?
- What does the @ symbol before a variable name mean in C#? [duplicate]
- Will using ‘var’ affect performance?
- Error: “Cannot modify the return value” c#
- Use a variable from another method in C#
- How to use Global Variables in C#?
- Formatting a float to 2 decimal places
- Implicit typing; why just local variables?
- .NET Integer vs Int16?
- How do I name variables dynamically in C#?
- How do you get a variable’s name as it was physically typed in its declaration? [duplicate]
- Does C# support a variable number of arguments, and how?
- Regarding local variable passing in Thread
- Variables within app.config/web.config
- C#: Getting size of a value-type variable at runtime?
- Getting variable by name in C#
- How do you pass variables from c# to javascript?
- Calling a Variable from another Class
- Should you access a variable within the same class via a Property?
- ASP.NET C# Static Variables are global?
- How to convert HTML to PDF using iTextSharp
- Usage of ‘&’ versus ‘&&’
- What is the equivalent of memset in C#?
- Many-to-many mapping table
- .net XML Serialization – Storing Reference instead of Object Copy
- Practical uses for the “internal” keyword in C#
- Programs randomly getting System.AccessViolationException