Skip to content

Instantly share code, notes, and snippets.

@mishrsud
Last active February 19, 2019 00:49
Show Gist options
  • Save mishrsud/c8eed9afd99270d8f0e66243752fa8d0 to your computer and use it in GitHub Desktop.
Save mishrsud/c8eed9afd99270d8f0e66243752fa8d0 to your computer and use it in GitHub Desktop.
// Great explanation on Stackoverflow: https://stackoverflow.com/a/1710395/190476
void Main()
{
Predicate<Person> personWithId1 = person => person.Id == 1;
Predicate<Person> personsOver30 = person => person.Age > 30;
var persons = new List<Person>
{
new Person {
Id = 1,
Age = 35,
Name = "Thirty Five"
},
new Person {
Id = 2,
Age = 24,
Name = "Twenty Four"
},
new Person {
Id = 3,
Age = 30,
Name = "Thir Ty"
},
new Person {
Id = 4,
Age = 40,
Name = "For Ty"
},
};
persons.Find(personWithId1).Dump("Id 1");
persons.FindAll(personsOver30).Dump("Over 30");
}
// Define other methods and classes here
class Person
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment