我有一个 powershell 类,我需要传递对 UInt64 变量的引用并从方法返回一个值。我正在尝试执行类似于下面代码的操作,但它给了我一个语法错误。
也许我不需要添加?[参考]?因为所有变量在 powershell 中默认都是引用,包括 uint64?但我只是不确定这是否属实......如果我遵循正常的 C 语言约定,那么该方法将获取参数的副本,而不是对变量的实际引用。我似乎记得 C# 中有关装箱和拆箱 int 类型的内容......C# int 类型的装箱和拆箱 https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxingPowershell 类方法的装箱 Int 是如何工作的?
class PowerHe11 {
# Constructor
PowerHe11() {
}
[void]AccessChannel(
[UInt64]$ichan,
[UInt64]$idata,
[UInt64]$isize,
[UInt64]$ireal,
[ref][UInt64]$otimeout,
[ref][UInt64]$odata,
[ref][UInt64]$ochan,
[ref][UInt64]$osize
) {
$osize = 64; #Return this value to caller of method
}
}
错误信息是:
At C:\Users\wmoore\Documents\fpga\zynq_pl\run_ps1\Untitled1.ps1:13 char:11
+ [ref][UInt64]$otimeout,
+ ~~~~~~~~
Multiple type constraints are not allowed on a method parameter.
At C:\Users\wmoore\Documents\fpga\zynq_pl\run_ps1\Untitled1.ps1:14 char:14
+ [ref][UInt64]$odata,
+ ~~~~~~~~
Multiple type constraints are not allowed on a method parameter.
At C:\Users\wmoore\Documents\fpga\zynq_pl\run_ps1\Untitled1.ps1:15 char:14
+ [ref][UInt64]$ochan,
+ ~~~~~~~~
Multiple type constraints are not allowed on a method parameter.
At C:\Users\wmoore\Documents\fpga\zynq_pl\run_ps1\Untitled1.ps1:16 char:14
+ [ref][UInt64]$osize
+ ~~~~~~~~
Multiple type constraints are not allowed on a method parameter.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MultipleTypeConstraintsOnMethodParam