namespace SnakesAndLadders
{
class Node
{
int snakeHead ; // points to another node where the player goes down to
int ladderFoot; // points to another node where to player goes up to
}
class Program
{
Node[] gameBoard = new Node[100];
void loadStructure()
{
// first, set all the snakeheads and ladderFoots to zero
for (int i =0; i < 100; i++)
{
gameBoard[i].snakeHead = 0;
gameBoard[i].ladderFoot = 0;
}
}
static void Main(string[] args)
{
}
}
在C#中,這不起作用。對於gameBoard [i],intellisense並未顯示它具有蛇頭組件。爲什麼不能像C++中的結構那樣訪問C#中的類的某些部分?
'snakeHead'是一個私有字段.. – stuartd
默認情況下,除非字面上聲明爲'public',否則所有類都是'private',其成員變量也是如此。 – MethodMan