>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 ---