I'm trying to list all the words with 4 letters. But I'm not sure why it's not working. It will not display it.
This is the code:
IEnumerable<string> query4 = words
.Where(n => n.Length == 4)
.Select(n => n);
DisplayArray(query4);
This is my display method:
private static void DisplayArray<T>(T[] array)
{
foreach (T item in array)
Console.WriteLine(item);
}
query4isn't an array. Either change your method to takeIEnumerable<T>or useToArray.IEnumerable<T>that only represents a sequence that is not set and you have to materialize it by using aforeachorToListorToArray. Until then it doesn't actually do the filtering or projecting. Also it will do the filtering and projecting each time you materialize it. That's why you'll see a lot of Linq queries ending with aToList.