Skip to content

Instantly share code, notes, and snippets.

@PhiHuyHoang
Created September 12, 2018 21:56
Show Gist options
  • Save PhiHuyHoang/cc5ebbeaf447461a94f0138ee7421366 to your computer and use it in GitHub Desktop.
Save PhiHuyHoang/cc5ebbeaf447461a94f0138ee7421366 to your computer and use it in GitHub Desktop.
method constructor function example C#
List<string> entries;
public Logger()
{
entries = new List<string>();
AddLogMethod(msg => entries.Add(msg)); //or we can use: AddLogMethod(entries.Add);
}
//Example for Func
public List<string> Filter(Func<string,bool> condition)
{
if(condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
return entries.Where(condition).ToList();
}
//Example for Predicate
public List<string> Filter(Predicate<string> condition)
{
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
return entries.FindAll(condition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment