Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using var benefits
Message
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:
01512470
Vues:
82
>Well it works because you have explicitly defined the return type to be a string. No benefit there in not just using 'string text = ' in the first place - I'd consider that more readable? What about something like:
public static ?? PickSomePeople(List<Person> people)
>    {
>        var v = people
>            .Select(p => new { p.Name, p.Age });
>        return v;
>    }
What return type can you use there except dynamic? Maybe it's a matter of taste - I'll stick to using var only for anonymous

You can use object :-)

No, it's not going to solve problems as return types or parameters. The point is that for the most part it saves typing especially for long generic types.

Both ways are equally fine - the compiler turns it into the same thing... I prefer it because it's less verbose for long type names and just as readable because as you point out the type definition is usually close by (as in the return value or the new typeDef()).

Not that this means a whole lot, but both refactoring tools that I use (CodeRush/Refactor and Resharper) flag explicit variable declarations as a suggested refactoring.

+++ Rick ---
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform