Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using var benefits
Message
 
To
27/05/2011 14:28:19
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01512055
Message ID:
01512098
Views:
59
>
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform