我用谷歌搜索,但找不到满意的答案.我基本上试图让这段代码工作:
public List<WordEntry> WordDataBase = new List<WordEntry>();
public List<CharacterEntry> CharacterDataBase = new List<CharacterEntry>();
public List<Entry> SelectWhere<T>(System.Func<T, bool> predicate) where T : Entry
{
if (typeof(T) == typeof(WordEntry))
return WordDataBase.Where(predicate);
else if (typeof(T) == typeof(CharacterEntry))
return CharacterDataBase.Where(predicate);
else
return null;
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,WordEntry和CharacterEntry都是从Entry派生的.我得到编译器错误:
Error CS1503 Argument 2: cannot convert from 'System.Func<T, bool>' to 'System.Func<WordEntry, int, bool>'
Run Code Online (Sandbox Code Playgroud)
和
Error CS1503 Argument 2: cannot convert from 'System.Func<T, bool>' to 'System.Func<CharacterEntry, int, bool>'
Run Code Online (Sandbox Code Playgroud)
希望你能帮助我.提前致谢