string[] words = { "apple", "banana", "mango", "or", "pas", "grae" };
var result1 = words.TakeWhile((word, index) => index > word.Length ).ToList();
I am learning Linq and I am trying to get all the words where the index is grater than the length of the word.
For some reason I am getting empty list. index of or, pas, grae is more than the length. But I am not getting the results. What am I missing?
You are looking for
Where()–TakeWhile()will stop iteration the first time the predicate evaluates to false (as the name might suggest), which is the case on the first word for you, hence you got an empty list.