I love the Linq syntax and its power, but sometimes I just can't understand why things work as they work.
Like right now. I have the following piece of code:
Regex regex = new Regex( ... );
int result1 = stringList.Count(regex.IsMatch);
IEnumerable<string> result2 = stringList.Where (x => regex.IsMatch (x));
As you can see in the first query I can use the shorter method group 'regex.IsMatch', but in the second query I have to write 'x => regex.IsMatch (x)'.
As Count and Where both take the same argument of type
Func<string, bool>
I can't see why I get a compiler error when I do this:
IEnumerable<string> result2 = stringList.Where (regex.IsMatch);