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 functions. I want to write common function with dictionaryEntries
query condition passed as predicate.
For example:
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 stands for ???????????????
Thanks in advance
A predicate delegate is defined; it takes the IsPositive method as parameter. var filtered = data. FindAll(predicate); We pass the predicate to the FindAll method of a list, which retrieves all values for which the predicate returns true.
Predicate functions are functions that return a single TRUE or FALSE . You use predicate functions to check if your input meets some condition. For example, is. character() is a predicate function that returns TRUE if its input is of type character and FALSE otherwise.
Predicate in general meaning is a statement about something that is either true or false. In programming, predicates represent single argument functions that return a boolean value.
Func<Entry, bool> predicate
should work, where Entry
is type of entry
variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With