LINQ
SelectMany is a fascinating operator in LINQ to Objects. For one thing, it is not as intuitive as most other LINQ operators. MSDN says that SelectMany “projects each element of a sequence to an IEnumerable(T) and flattens the resulting sequences into one sequence.” I still remember reading this description of SelectMany for the first time, […]
I was discussing the little LINQ puzzle with Stephen Toub, and he brought up an idea which lead to another puzzle. I like this one even more than the previous one. Why does the last line throw StackOverflowException? IEnumerable<int> q = new int[] { 1, 2 }; q = from x in new int[] { […]
Why does the last line hang? IEnumerable<int> empty = Enumerable.Empty<int>(); for (int i = 0; i < 40; i++) { empty = empty.Concat(empty); } int[] emptyArray = empty.ToArray(); Answer in the comments section. For a slightly harder challenge, check out the next puzzle.
In responses to my last week’s post, several readers mentioned LINQ-like operators they implemented themselves. I also had ideas for operators that would lead to neat solutions for some problems, so I decided to give it some thought and collect up the most useful operators into a reusable library. My goal was to include operators […]
Continue reading about Extended LINQ: additional operators for LINQ to objects
Ever since I learned about LINQ, I keep discovering new ways to use it to improve my code. Every trick makes my code a little bit faster to write, and a little bit easier to read. This posting summarizes some of the tricks that I came across. I will show you how to use LINQ […]
Continue reading about 7 tricks to simplify your programs with LINQ
Recent Comments