views:

199

answers:

2

I want an extension method that needs to return non-vowel words.I designed

 public static IEnumerable<T> NonVowelWords<T>(this IEnumerable<T> word)
    {
        return word.Any(w => w.Contains("aeiou"));
    }

I received error as "T" does not contain extanesion method "Contains".

+14  A: 

You don't need to use a generic method if you're always dealing with strings.

public static IEnumerable<string> NonVowelWords(this IEnumerable<string> words)
{
    char[] vowels = { 'a', 'e', 'i', 'o', 'u' };

    return words.Where(w => w.IndexOfAny(vowels) == -1);
}
LukeH
+1  A: 

Try

public static IEnumerable<string> NonVowelWords<T>(this IEnumerable<string> word)
{
    return word.Where(w => !(w.Contains("a") || w.Contains("i") || w.Contains("u") || w.Contains("e") || w.Contains("o")));
}
Maximilian Mayerl
`Any` returns a `bool`, not an `IEnumerable<>`.
LukeH
I don't think NonVowelWords needs to be generic.
Shoko