VAR Keyword:-
At first glance, it appears that you’re declaring a variable of type “var”. Actually, “var” is not a type, but rather a new keyword that means, declare a variable, but not delcare its type”.
How this Works :-Type inference algorithm in the compiler analyzes your program and works out the type for you. Conceptually it is like going through your program for each occurrence of the keyword "var" and putting it in place of "var", after figuring out its type.
NO TYPES
// Before:
Dictionary<int, List<int>> Coeffs = new Dictionary<int, List<int>>();
// After:
var Coeffs = new Dictionary<int, List<int>>();
Performance
Variants in vb or any other lang use dynamic typing rather than inferring the type statically. Therefore, variants carried a runtime performance penalty. Using "var" in C# 3 does not. Your program will run just as quickly as if you had written the type in yourself.
source:-http://www.programmersheaven.com/2/CSharp3-1
No comments:
Post a Comment