@amantinband

❤documentation?
Deferred execution: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/classification-of-standard-query-operators-by-manner-of-execution#deferred
Task based asynchronous programming: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming

@danielkiesel4440

Really enjoyed the riddle and the explanation! Small correction, though, to avoid another bug. Enumerable.Range does not take a start and an end index but instead a start index and a count.
So only if the start index is 0, this happens to be to be the end index + 1.

@xlerb2286

That's a well done explanation and will help a lot of folk.  Thank you for taking the time to put this together.

Threading and all the weird race conditions, etc., that come along with it was my life for 5+ years up until a year ago.  I diagnosed so many bugs in other dev's code caused by misunderstandings of a similar nature to the one in this riddle that it was disturbing - and these weren't inexperienced devs.  Thankfully for the work I had to do async wasn't of much use but I sure did learn, sometimes painfully, the ins and outs of using Task ;)  But that's all somebody else's problem now. 🙂

@def1nt

I think, that in second example the actual object that is being assigned to IEnumerable<Task> is Array<Task> which has its own implementation of Count(), that is not being re-enumerated second time.

@petewarner1077

For the 2nd riddle, because the enumerable this time is an array of tasks, the Count() function is smart enough to use the fixed size of the array instead of re-iterating an enumerable with side effects. The code becomes deterministic. The array contains 2 completed tasks, and the output is "**2 Tasks completed!"

@MilanJovanovicTech

I love this format!

@diego_samano

This is a cool dynamic.

I understand the answer for using the array instead gives "**2 stars!".
This is happening because the Count() method has a couple of validations to try to avoid to enumerate the enumerable. So it's checking if the source has a property that has the quantity of elements and return it. Array is an ICollection so it has a Count property.

@gregorymorse8423

The answer is "**" followed by any possible interleaving of characters of "**" and "2 stars!" To be precise...

@ДенисЕгоров-ь3в

I love your voice. It's awesome. Thanks for videos

@wolfgangdiemer2511

I love such riddles. And to get a video solution, was much more, than i excepted.👍 
Its good to train or refresh such stuff, cause with all that syntactic sugar, its still important to know, what's under the hood.
More riddles, do it, just do it. DO IT🤙

@gui.ferreira

Excellent video! I hope to see you dissecting more of those challenges 👏

@mohammedelsuissey1745

Great video, never knew that enum.count() would re enumerate the enumerable if it was already enumerated in the previous line!!!

@NevenMilakara

Mind blowing! The best spent 11 minutes! :) Such a great example! :)

@briankarcher8338

Beware Count() - there be dragons!

I highly recommend people actually look at the code inside of the Count() function. It is extremely important. Only way you will fully understand this extremely important and easy-to-misuse function.

@Max_Jacoby

Once I made a property initialization like this Prop => new Something(); instead of Prop { get; } = new Something(); and stuck in debugging of my program for two days 😅 The lesson is don't use fancy lambdas when you create objects unless you want to confuse anyone who reads your code.

@davearkley7014

Love it, really well explained

@ITR

Haven't watched the video yet (paused at 0:11), but I'm going to guess:
1: it's not going to run syncronously because the select statement isn't evaluated before WhenAll is executed, but also because Console.Write isn't asyncronous. 
2: tasks.Count() uses the linq count, which just enumerates the enumerable to count it, which will return 0 because it's already been evaluated. Not sure if I'm mixing up IEnumerable and IEnumerator here.

EDIT: Oh, task is threaded, not asynchronous, got them mixed up. Then there's gonna be a race condition yea.
Also guess I did mix up IEnumerable and IEnumerator.

@OldWiseLlama

To nitpick, once you call Task.Run it doesn't start running the task immediately. The task is being enqueued to the task scheduler to be executed. Let's say your application is suffering from thread pool starvation. Then the tasks might wait a while before they get started.

@codewkarim

Thanks! More and more and more please!

@codahighland

I don't use C# a lot so I didn't know about the second enumeration, and I've never used C# tasks before. But the fact that you had results with four stars in the poll options gave away the punch line -- I know threadpools so I knew there was a race condition there.