繁体   English   中英

如何在包含变量的变量名称中存储信息?

[英]How do I store information in a variable name that contains a variable?

$DataApp2 = "SUCCESS FINALLY"
$Type = "App2"

$Data = Get-Variable -Name "Data$Type" -Value
Set-Variable -Name "Button$Type" -Value "$Data"
$ButtonName = Get-Variable -Name "Button$Type" -Value
$DefaultForm.Text = "$ButtonName"

因为现在可能更明显了,我打算调用一个函数,该函数除了给定的变量外什么也不做

真心感谢您rokumaru乳液您不知道您对我有多大帮助

您可以使用Set-VariableInvoke-Expression

Set-Variable -Name "Button$Type" -Value "test"
Invoke-Expression "`$Button$Type = 'test'"

但我建议使用哈希表,因为它安全且快速。

$h = @{}
$h."Button$Type" = "test"
$h.ButtonApp2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM