我在函数 Doit 中使用此代码收到这些错误(我正在运行.Net 3.5):
错误 1: The best overloaded method match for 'LoadPref<A>(string, System.Func<string,A>, A)' has some invalid arguments
错误 2: Argument '2': cannot convert from 'method group' to 'System.Func<string,A>'
class A : SomeObject
{
}
static class Utilities
{
private T LoadPref<T>( string key, Func<string, T> loaderFunc, T defaultValue )
{
if ( Prefs.HasKey( key ) )
{
return loaderFunc( Prefs.GetString( key ) );
}
return defaultValue;
}
private T LoadAsset<T>( string assetPath ) where T : SomeObject
{
return (T)LoadAssetInSomeWay( assetPath );
}
private void Doit()
{
A asset = LoadPref<A>( "key", LoadAsset, null );
}
}
有谁知道出了什么问题?