You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell 7中如何使用[Func[int[], int]]委托类型?

PowerShell中[Func<int[], int>]的正确使用语法

在PowerShell里,[Func[int, int[]]]这类泛型委托能正常调用,但使用[Func[int[], int]]时会报错:

InvalidOperation: Unable to find type [Func].

相关命令输出参考

  • 执行[Func[int, int]] | Format-Table -Hide,输出:True True Func2 System.MulticastDelegate`
  • 执行[Func[int, int[]]] | Format-Table -Hide,输出:True True Func2 System.MulticastDelegate`
  • 执行[Func[int[], int]] | Format-Table -Hide,输出:InvalidOperation: Unable to find type [Func].

问题原因与解决方法

这是PowerShell解析泛型类型时的语法歧义导致的:当泛型参数是数组类型时,PowerShell会错误地把[]识别为整个Func类型的数组后缀,而非泛型参数的一部分。

正确写法需要用括号包裹数组类型的泛型参数,明确解析范围:

[Func[[int[]], int]]

执行上述语法就能正常获取到对应的泛型委托类型,不会再抛出错误。

内容的提问来源于stack exchange,提问作者Methodox Charles Zhang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 07:52:05