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:
01513628
Views:
52
>>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 :-)

But if you use object you only have the minimal object properties and methods. At least with dymanic you can use the true properties and methods of the class (if you're prepared to believe that's what you are dealing with. Perhaps Tuples are another option.
If I can declare the class type I'd rather do that then save on typing. It will still be lead to more readable code for any other programmer coming across it.
Anyway - each to his own :-}

>
>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 ---
Previous
Reply
Map
View

Click here to load this message in the networking platform