Let's say I have array Grid that was initialized with
$Grid = @(@(1..3), @(4..6), @(7..9))
and I want to change Grid[0][0] to value "Test" but I want to make it unchangeable, is there a way I could to that?
So far I've tried playing around with classes that allow read-only or constant declarations through the class as opposed to using New-Variable/Set-Variable but it doesn't affect the index itself but the individual element as in
$Grid[0][0] = [Array]::AsReadOnly(@(1,2,3))
$Grid[0][0] # 1 \n 2 \n 3
$Grid[0][0].IsReadOnly # True
$Grid[0][0] = "test"
$Grid[0][0] # test
I assume this is due to $Grid[0][0] being read-only as opposed to constant and the behaviour I experienced supported that:
$test = [Array]::AsReadOnly(@(1,2,3,4))
$test[0]=1 # Errors
$test = "test"
$test # test
$Grid = @(@(1..3), @(4..6), @(7..9))
$Grid[0][0] = [Array]::AsReadOnly(@(1,2,3))
$Grid[0][0][0] = 1 # Errors
$Grid[0][0] = "test"
$Grid[0][0] # test
I'm not sure what to try next and I know that this is very simple with classes but I am not looking for that as a solution.
$grid) is still just a regular array. Given PowerShell's love for enumerating/flattening array expressions, this is going to become near-unreadable to construct as a literal - can you perhaps describe the underlying problem you're trying to solve instead?$var = valueas opposed to usingSet-Variableand nv. I'm not sure how else to describe this in generality but if you have any specific questions I can answer them.