为什么这段代码没有编译?

sir*_*val 0 c#

我在函数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 );
    }
}
Run Code Online (Sandbox Code Playgroud)

谁知道什么是错的?

Gre*_*Ros 5

您需要更改LoadAssetLoadAsset<A>使泛型正常工作.