Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get file owner
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01482984
Message ID:
01482994
Vues:
52
>
>Can I ask you about the use of the Var type there? I know that was a new feature in C# 3.0 but thought it was for occasions when the type is unknown at compile time. Given your expertise I am sure there is a good reason.

No, it's just a shortcut to tell the compiler to infer the type based on the method you are calling. It's still strongly-typed and known at compile time. One of the things I thought was really dumb when I started using .NET was how redundant statements like this were:
StringBuilder sb = new StringBuilder();
You mean the variable is a StringBuilder - nah, no kidding?! Apparently other people thought this was silly as well and they gave us var - the compiler infers the type based on the type being created or returned by a method. OK, so they didn't give it to us for that reason, it was needed for anonymous types. But it's still a welcome addition.

This is equivalent:
var sb = new StringBuilder();
If you don't know the type at compile time then you would use the new "dynamic" type.
-Paul

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

Click here to load this message in the networking platform