Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using var benefits
Message
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:
01512470
Views:
81
>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?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform