Comment on Real quick question about the "break"
m_r_butts@kbin.social 11 months agoFine:
var enumerable = Enumerable.Range(0, 100)
.Where(i => i % 2 != 0)
.TakeWhile(i => i < JUST_THE_WORST_NUMBER);
foreach (int i in enumerable)
{
Console.WriteLine(i);
}
olsonexi@lemmy.wtf 11 months ago
idk, maybe C# just doesn’t have great syntax for the way you’re doing it or something, but I think the simplest solution is the most readable in this case:
m_r_butts@kbin.social 11 months ago
I came up with a contrived example for the sake of illustration, and deliberately chose to use LINQ to build the enumerable because of how valuable it can be in filtering and ordering data. Where and TakeWhile alone can replace a whole lot of continues and breaks.
Your code does the same job as my first example, and it's simpler, and maybe that's more appropriate for the class.