gpt4 book ai didi

PowerShell HashTable - 初始化期间的自引用

转载 作者:行者123 更新时间:2023-12-04 06:56:05 29 4
gpt4 key购买 nike

我有一个理论问题 - 如何在初始化期间引用哈希表,例如,计算基于其他已声明成员的成员。

Remove-Variable myHashTable -ErrorAction Ignore
$myHashTable =
@{
One = 1
Two= 2
Three = ??? # following expressions do not work
# $This.One + $This.Two or
# $_.One + $_.Two
# $myHashTable.One + $myHashTable.Two
# ????
}

$myHashTable.Three -eq 3 # make this $true

任何想法如何做到这一点?真的有可能吗?

编辑:
这是我的解决方案:
$myHashTable = 
@{
One = 1
Two= 2
}
$myHashTable.Three = $myHashTable.One + $myHashTable.Two

最佳答案

你也可以重复这个...
有时当哈希表很长时
并且只能在 2 或 3 次重复中定义...
工作正常:

$AAA = @{
DAT = "C:\MyFolderOfDats"
EXE = "C:\MyFolderOfExes"
}

$AAA += @{
Data = $AAA.DAT + "\#Links"

Scripts = $AAA.EXE + "\#Scripts"
ScriptsX = $AAA.EXE + "\#ScriptsX"
}

  • Note in the second part we are just adding ( += )
    more items to the first part...

    but now... we can refer the items
    in first part of the hashtable

关于PowerShell HashTable - 初始化期间的自引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38685672/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com