I want to select all the words from a list whose length is less or equal to 5. My current code only returns this:
I want the result to be the actual words.
static void Main()
{
string[] words = { "hello", "Welcome", "Rolling", "in", "The", "Deep" };
var shortWords = from word in words select word.Length <= 5;
foreach (var word in shortWords) {
Console.WriteLine(word);
}
Console.Read();
}
Looks like you meant to do
var shortWords = from word in words where word.Length <= 5 select word;
or just
var shortWords = words.Where(word => word.Length <= 5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With