Type inference occurs in many places in C #, at least the following:
- A keyword
varthat tells the compiler to infer (infer) the correct type of a variable from what you initialized with - Ability to leave type parameters from a general method call if they can be inferred from parameters
- Ability to leave types from arguments of lambda expression if they can be deduced
And to answer your questions:
1) This saves a lot of input, especially when using the so-called "LINQ methods". Compare for example
List<string> myList = new List<string>();
IEnumerable<string> result = myList.Where<string>((string s) => s.Length > 0)
.Select<string, string>((string s) => s.ToLower());
against
var myList = new List<string>();
var result = myList.Where(s => s.Length > 0).Select(s => s.ToLower());
2) , "", var , ( object dynamic), .
3) , . . , , , , .
4) , 3) .