0
Why not just use the var keyword as the type of the parameters passed in the method? Then we could call the function passing arguments of whatever type we would like. Could that work?
3 Réponses
+ 6
As var is NOT a datatype in C# you cannot use it as a return parameter.
+ 4
Essentially 'var' is just a way for the programmer to say:
"Hey C# compiler, please figure out the real type of this variable and replace 'var' with it's actual type"
var greeting = "bonjour";
compiles to the same object/IL code as:
string greeting = "bonjour";
It is one of the 'syntactical sugar' constructs of the C# language that generally improves productivity.
Ninjas don't like 'var'.
- 2
This ketwird is only helper to ,creating the fields