LINQ query expressions differences

by Marius Gheorghe 29. February 2008 16:03
Much to my surprise, once i started digging, it seems that the difference between the C# and VB.NET implementation of query expressions are quite big. Case in point : C# doesn't support the "distinct" clause and VB.NET does.
Also the compiler is quite "strict" when you're using expressions :
var g = from w in words where w.Length > 5 .Distinct() select w; This seems a valid query (especially when you "map" logically query expressions to SQL) except it won't compile. It will crap out with a totally uninformative and wrong error message. On the other hand, this will compile and run just fine :
var g = from w in words .Distinct() where w.Length > 5 select w; The point i'm trying to make is that it seems to be "easier" to write code using query operators directly instead of query expressions. The code will be longer but when you read it you won't have to switch back and forth mentally from different query expression implementations :
var g = words.Distinct().Where((string w) => w.Length > 5);

Tags:

dotNET

Comments are closed

marius gheorghe

developer, dad, gamer

Contact me

My Resume

Favourite Tools