Powershell initialize strings in a loop

  Kiến thức lập trình
$formFields = @("UserSurname","UserFirstName")

 foreach ( $field in $formFields ) {

    $($field+"Label") = New-Object system.Windows.Forms.Label
    $($field+"Label").Width = 25
}

I’m trying to initialize a bunch of form items from a string of components. I just don’t understand how to initialize a variable from another value in a loop. I have tried many things but I think this code best illustrates what I am trying to do.

Just can’t seem to construct the right values in the loop

New contributor

Craig Urton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT