繁体   English   中英

方法或委托参数与委托参数不匹配

[英]Method or delegate parameters do not match delegate parameters

我正在执行一些异步缓存,并且使用一个简单的Action回调来使系统其余部分知道缓存何时完成。


入口点(导致错误的行):

this.StartCoroutine<Action>(SceneUtils.CacheSceneNames, PopulateButtons);

协程方法:

public static IEnumerator CacheSceneNames(Action completedCallback) {}

回调方法:

private void PopulateButtons() {}

最后,启动协程的方法:

public static Coroutine StartCoroutine<T>(this MonoBehaviour extends, Func<IEnumerator, T> method, T value) {}

据我所知,所有参数和返回类型都是正确的,但是出现以下错误:

error CS0123: A method or delegate `CacheSceneNames(System.Action)' parameters do not match delegate `System.Func<System.Collections.IEnumerator,System.Action>(System.Collections.IEnumerator)' parameters

谁能指出我做错了什么? 这可能是协方差问题吗?

我认为您想在StartCoroutine<T>的参数列表中指定Func<T, IEnumerator> method而不是Func<IEnumerator, T> method

它是Func<T, TResult> :返回类型是最后一个类型参数-并且您的CacheSceneNames接受ActionT )参数并返回IEnumerator

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM