C# declaration style in X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4584
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 test
chris(at)xsharp.eu
FFF
Posts: 1532
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.19, X#2.19.0.2.)
Post Reply