Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using var benefits
Message
 
À
27/05/2011 14:28:19
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows XP SP2
Divers
Thread ID:
01512055
Message ID:
01512098
Vues:
60
>
>I don't think there is any performance difference; however, my preference is to use var only in Linq....which is what is was designed for since linq queries change the typing..

Sorry to be nitpicky here, but people could easily misunderstand the, "linq queries change the typing" comment and what var does. LINQ queries return an anonymous type - at compile time the compiler generates a type with a unique name. It has access to this name/type, but we don't (so we wouldn't be able to put the correct type in), hence the term "anonymous type". Since we don't have access to the correct type name they had to come up with some way of handling this - "var" which basically defers the type to the compiler - it will fill in "var" with the correct type at compile time (not at runtime).
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform