List<bool> test = new List<bool>();
test.Sort(new Func<bool, bool, int>((b1, b2) => 1));
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
错误2参数1:无法从'System.Func'转换为'System.Collections.Generic.IComparer'
错误1'System.Collections.Generic.List.Sort(System.Collections.Generic.IComparer)'的最佳重载方法匹配有一些无效的参数
当我有
private int func(bool b1, bool b2)
{
return 1;
}
private void something()
{
List<bool> test = new List<bool>();
test.Sort(func);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常.他们不是一回事吗?
usr*_*usr 11
Func是错误的委托类型.您可以使用以下任一方法:
test.Sort((b1, b2) => 1);
test.Sort(new Comparison<bool>((b1, b2) => 1));
Run Code Online (Sandbox Code Playgroud)