I want to create new HashTable repeatedly in PowerShell

Asked 1 years ago, Updated 1 years ago, 380 views

This is an additional question for This questionHere is the code you answered:

#Associative Array Creation
Function makeHashTable{
    Param(
        param1,
        param2
    )
    for ($i by index number) {
        $value=@()
        foreach($vin$values){
            $str = Abbreviated
            $value+=$str
        }
        $HashTable.Add ($List[$i], $value)
    }
}

# Button 2 Processing
Function Calc {
    $HashTable Processing
}

approximately

# create associative sequences here
$HashTable=[System.Collections.General.Dictionary [String, PSObject]]:new()

# ASSOCIATIVE ARRAYING BUTTON
$Button1 = Abbreviated
$Button1.Add_Click({makeHashTable param1param2})

# button for passing associative array
$Button2 = Abbreviated
$Button2.Add_Click({Calc})

Currently, I'm creating a string in the list box that I set as an associative array by clicking Button 1.
There is no problem with the linked method as long as it is done once, but if you add a new string or re-enter everything and create an associative array in Button1, I think the key will be updated or duplicated.
What should I do if I want to be able to create a new HashTable more than once by clicking Button 1?

As for me, it is easy to understand how to create and hand it over within a function.
However, the variable $HashTable is generated within the function, but it is valid only within the function and cannot be seen from the outside, so it seems difficult...
If you know a good way, please take care of me.

powershell

2022-11-19 16:03

1 Answers

Before you operate the $HashTable, call the Dictionary.Clear() method and empty it.


2022-11-19 16:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.