C# declaration style in X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C# declaration style in X#

Post 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()
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C# declaration style in X#

Post 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.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply