简体   繁体   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"

as it may be more obvious now i intended to call a function that does something with nothing but the variables its given 因为现在可能更明显了,我打算调用一个函数,该函数除了给定的变量外什么也不做

seriously thank you rokumaru and lotpings you have no clue how much you have helped me 真心感谢您rokumaru乳液您不知道您对我有多大帮助

You can use Set-Variable or Invoke-Expression . 您可以使用Set-VariableInvoke-Expression

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

but I recommend using a hashtable because it is safe and fast. 但我建议使用哈希表,因为它安全且快速。

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

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

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