原文地址:https://support.unity3d.com/hc/en-us/articles/207157773-What-is-CS1624-
症状
当尝试进入Play模式时,我得到了如下错误:
error CS1624: The body of `__’ cannot be an iterator block because `__’ is not an iterator interface type
原因
当使用了迭代器访问器,但是返回类型却不是如下迭代器接口类型中任何一种:IEnumerable
,IEnumerable<T>
,IEnumerator
,IEnumerator<T>
。
本例子在一个返回类型为“void”的WaitCheck方法内,使用了迭代器访问器开启了一个协程。
本例的错误信息如下:
error CS1624: The body of `ExampleScript.WaitCheck()’ cannot be an iterator block because `void’is not an iterator interface type
解决方案
想解决CS1624错误,你需要使用其中一种迭代器接口类型作为返回值类型。
想修复本例子,只要修改WaitCheck方法的返回值类型为IEnumerator迭代器接口类型。
更多信息
https://msdn.microsoft.com/en-us/library/7e87ybkb(v=vs.90).aspx