How to pass a predicate to work in C #?

I have:

 public void InitializeStatusList(DropDownList list)
    {
       var dictionaryEntries = GetEntriesFromDatabase();
       list.DataSource = dictionaryEntries.Where(entry => entry is EntryStatus1 || entry is EntryStatus2);
       list.DataBind();           
    }

I have many of these features. I want to write a generic function with a query condition dictionaryEntriespassed as a predicate.

For instance:

public void InitializeStatusList(DropDownList list)
{
    CommonInitializeStatusList(DropDownList list, entry => entry is EntryStatus1 || entry is EntryStatus2);
}

public void CommonInitializeStatusList(DropDownList list, ??????????????? predicate)
{                       
    var dictionaryEntries = GetEntriesFromDatabase();
    list.DataSource = dictionaryEntries.Where(predicate);
    list.DataBind();        
}

What does it mean ???????????????

Thanks in advance

+5
source share
2 answers

Func<Entry, bool> predicateshould work, where Entryis the type of the variable Entry.

+13
source

You can do the following:

public void InitializeStatusList(DropDownList list)
{    
    Func<Entry,bool> predicate=entry=>entry is EntryStatus1 || entry is EntryStatus2;
    CommonInitializeStatusList(list, predicate);
}

public void CommonInitializeStatusList(DropDownList list, Func<Entry,bool> predicate)
{                                 
    var dictionaryEntries = GetEntriesFromDatabase();    
    list.DataSource = dictionaryEntries.Where(predicate);
    list.DataBind();

}
+6
source

All Articles