I would like to reference a single element inside an array, using the [ref] keyword.
How to test for a reference:
$var1 = "this is a string"
[ref]$var2 = [ref]$var1
$var2.Value
this is a string
$var2.Value += " too!"
$var2.Value
this is a string too!
$var1
this is a string too!
The above is working as expected. But now to reference a single element inside any array?
$var3="string 1", "string 2", "string 3"
[ref]$var2=[ref]($var3[1])
$var2.Value
string 2
$var2.Value += " updated!"
$var2.Value
string 2 updated!
$var3[1]
string 2
I expected $var3[1]
to return the same as the value of $var2.Value
. What am I doing wrong?