xsharp.eu • C# declaration style in X# - Page 2
Page 2 of 2

C# declaration style in X#

Posted: Fri Oct 18, 2019 9:07 pm
by Chris
Robert van der Hulst wrote:Chris,

Take this example.

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 !
What should the type of oAll be ?
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
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! :)

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

C# declaration style in X#

Posted: Fri Oct 18, 2019 9:18 pm
by FFF
Chris, Robert,
taking the sample with linq, yes, VAR is the easy way out.
But: usually you define a variable to use it later on. Now, what may I expect oAll: to give? What shall be shown by intellisense?
Anyway, a select returns a set of tuple, so a classic Vo-style array could hold it.