✅ 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?
2 Replies
nightooi /s I'm rarely serious
thinks me gets it, you have to iterate over the dictionary first? or it Dict.Keys will return a firstordefault value where the takewhile will be applied to the first string.. nope not it
Vi Ness
Vi Ness10mo ago
Are you trying to get all of the keys that contain "something" or only the ones at the very beginning of the collection?
Want results from more Discord servers?
Add your server