Skip to content

Instantly share code, notes, and snippets.

@h09shais
Created November 8, 2018 09:23
Show Gist options
  • Save h09shais/72dbd8d5510d57bc70896076337f65d1 to your computer and use it in GitHub Desktop.
Save h09shais/72dbd8d5510d57bc70896076337f65d1 to your computer and use it in GitHub Desktop.
C# Action, Predicate and Func
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