我有:
public void InitializeStatusList(DropDownList list)
{
var dictionaryEntries = GetEntriesFromDatabase();
list.DataSource = dictionaryEntries.Where(entry => entry is EntryStatus1 || entry is EntryStatus2);
list.DataBind();
}
我有很多这样的功能。我想用作为谓词传递的 dictionaryEntries
查询条件编写通用函数。
例如:
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();
}
什么代表????????????????
提前致谢
最佳答案
Func<Entry, bool> predicate
应该工作,在哪里 Entry
是 entry
的类型变量。
关于c# - 如何将谓词传递给 C# 中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10530669/