C# declaration style in X#
Posted: Fri Oct 18, 2019 9:07 pm
Robert, yes I agree this is the one of two places where it is better to use VAR. But then again, I wish Linq was not a thing at all, either!Robert van der Hulst wrote:Chris,
Take this example.
What should the type of oAll be ?Code: Select all
LOCAL oDev := GetDevelopers() as IList<Developer> LOCAL oC := GetCountries() as IList<Country> LOCAL oAll := FROM D IN oDev ; JOIN C IN oC ON D:Country EQUALS C:Name ; ORDERBY D:LastName ; SELECT CLASS {D:Name, D:Country, C:Region} // Anonymous class !
I think using VAR oAll make a lot of sense here.
Btw the answer is (the last time I checked)
Code: Select all
IOrderedEnumerable<<>f__AnonymousType0<Developer,Country,String>>
Robert
The other place is FOREACH, because some of the items for some collections can be similarly diffciult to strongly type, I can nderstand using VAR in thos cases.
But IMO this is bad
VAR i := 1
and this is VERY bad (again IMO of course)
VAR o := somevar:SomeMethod()