© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
nightooi /s Im rarely serious

✅ Takewhile in foreach iterator exiting without iterating over the elements.

foreach(var i in this.SomeDict<string, object>.Keys.TakeWhile(x => x.Conains("somestring")))
{
//do work.
}

i know for a fact that there are string containing "somestring". During debugging the debugger just stepps into the TakeWhile, returns twice to dict, goes into in once and then just skips the inner block. The I variable is being resolved to a string, and the result of the takewhile is a ienumerable, so why does it skip iterating over the returned elements?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Iterating over AsyncEnumerable and writing to MemoryStream
C#CC# / help
3y ago
❔ Foreach
C#CC# / help
3y ago
❔ How to rewrite this without second foreach?
C#CC# / help
3y ago
Try-catch in an iterator
C#CC# / help
16mo ago