我想出了数组,但现在我想写入我的 $CreateGrid[1,1] 的值,例如
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 "+---+---+---+---+---+---+---+---+---+---+ "
但是,当我尝试这个时,我得到以下值的输出:
( 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])
我将如何解决这个问题?还是有更聪明的方法?简而言之,我想在上面显示的网格中包含数组的位置值。
编辑:
$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"
}
}