I read that the 'if' keyword is evil, and better to use predicate to replace if. Then I googled, but still dont get it.
Can anyone be kind to provide an example?
No matter what they say, if is not evil. There may be specific cases for which a Predicate is a better choice than an if (or a set of ifs).
For example,
foreach (Foo f in fooList) {
if (f.Equals(fooTarget)) {
return f;
}
}
versus (.NET 2.0)
fooList.Find(delegate (Foo f) { return f.Equals(fooTarget); });
or (later)
fooList.Find(f => f.Equals(fooTarget));
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