Created
September 12, 2018 21:56
-
-
Save PhiHuyHoang/cc5ebbeaf447461a94f0138ee7421366 to your computer and use it in GitHub Desktop.
method constructor function example C#
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
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