Created
November 8, 2018 09:23
-
-
Save h09shais/72dbd8d5510d57bc70896076337f65d1 to your computer and use it in GitHub Desktop.
C# Action, Predicate and Func
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Action<string> Print = item => Console.WriteLine(item); | |
// void Print(string item) => Console.WriteLine(item); // To local function | |
var items = new List<string> { "Apple", "Mango", "Banana" }; | |
items.ForEach(Print); | |
Predicate<string> Predicate = item => item.Length > 5; | |
// bool Predicate(string item) => item.Length > 5; // To local function | |
var result = items.FindAll(Predicate); | |
result.ForEach(Print); | |
Func<string, bool> FindAll = item => item.Length > 5; | |
// bool FindAll(string item) => item.Length > 5; // To local function | |
var results = items.Where(FindAll).ToList(); | |
results.ForEach(Print); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment