C#: 19-Predicate Functions

always returns a boolean

Main logic

ShowGrade("");


 

Method using predicate

static void ShowGrade(string name)
{
    //Predicate logic
    var found = employees.Find(predicate);
    Console.WriteLine("{0}'s Grade: {1}", found.Name, found.Score);
} 


 

Predicate Method

static bool predicate(Employee employee)
{
    //can return the condition instead of doing evail with if/then
    return (employee.Name == "Jones");

    //if (employee.Name == "Jones")
    //    return true;
    //else
    //    return false;
}
Tags