I figured the array out, but now I want to Write-host the value of my $CreateGrid[1,1] for example to
Write-host " A B C D E F G H I J "
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 1"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 2"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 3"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 4"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 5"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 6"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 7"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 8"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| | | | | | | | | | | 9"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
Write-host "| $CreateGrid[1,1] | | | | | | | | | | 10"
Write-host "+---+---+---+---+---+---+---+---+---+---+ "
However when I try this, I get the following output for the value:
( System.Object[] System.Object[] System.Object[] System.Object[] System.Object[] System.Object[] System.Object[] System.Object[] Syst
em.Object[] System.Object[] System.Object[] [1,1])
How would I go around this? or is there a more clever way?
In short I want to include the positional value of the array in the Grid shown above.
EDIT:
$CreateBoard = New-object "Array[,]" 10,10
Function Add-ToColumn{
param ([Int] $columnnum,[String] $player)
PROCESS{if (0..9 -notcontains $columnnum){"Invalid move";return}
#0 is the bottom, 9 is the top
for($i = 0; $i -le 9; $i++)
{
if ($CreateBoard[$columnnum, $i] -eq $null)
{
$CreateBoard[$columnnum, $i] = $player
"Coin placed in $columnnum, $i coins in the column!"
return
}
}
#if you get here, column is full
"Invalid move"
}
}
When you put an expression in a double quoted string, the parser stops at the first non-variable name character. So:
is processed as if it were
and as
$CreateGridis (or at least appears to be) an array it performs aToStringon each member and concatenates the results (as this is a two dimensional array, each enumerated member is an array, henceSystem.Object[]multiple times).If you use the expression syntax (
$(...)) inside the string the whole contained expression is processed as a PowerShell expression (eg. you can put a pipeline in there):