我有以下 PowerShell 片段:
$property = @{
Getter = { 80 };
}
$value = $property.Getter.Invoke()
$value.GetType() # Shows Name = Collection'1 instead of int
我希望$value.GetType()回傳,Int32但它回傳一個集合。
我不能只取元素,[0]因為有時 Getter 函式會回傳一個陣列。
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
您可以通過這種方式嚴格宣告回傳值的型別。例如,回傳型別將是Double:
cls
$property = @{
Getter = [Func[Double]]{ 80 }
}
$value = $property.Getter.Invoke()
$value.GetType().Name
# Double
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/327012.html
標籤:电源外壳
