似乎无法在Unity c3中使用Func
本文关键字:Func c3 Unity | 更新日期: 2023-09-27 18:34:16
如果我试试这个
private System.Action blah;
它工作正常。出于某种原因
private System.Func blah;
资产/脚本/对象/列表组/大规模解释.cs(130,24):错误 CS0234:系统
Func' does not exist in the namespace
的类型或命名空间名称。是否缺少程序集引用?
我不明白,为什么我不能用Func
? 这是普通的最新 Unity 中。
有Action
类型,因为它是封装不返回值的方法的方法。
没有称为 Func
的类型,因为它始终返回某个值,您需要指定其值的类型。例如Func<int>
.
实际上,Func
至少需要一个泛型类型作为委托的返回类型。
private System.Func<bool> simple;
private System.Func<bool, int, double> withParams;
用法:
bool result = simple();
bool result = withParams(10, 0.2);
如果不需要返回类型,请使用 Action
。