public static void DoSomething<TObj>(IEnumerable<TObj> |
which takes a predicate parameter and only perform the action if the predicates is true.
We can pass in anonymous delegate for the predicate:
List<string> listOfStrings = new List<string>(); listOfStrings.Add("one"); listOfStrings.Add("two"); listOfStrings.Add("three"); AnonymousDelegate.DoSomething<string>(listOfStrings, delegate(string s) { Response.Write(s + "<br/>");}, delegate(string s) { return !s.StartsWith("o"); }); |
In this case on "two" and "three" would be written out.
No comments:
Post a Comment