我正在嘗試爲我的程序做一些簡單的類,並且我被我的Tile [,]類'theGrid'對象的字段類型錯誤的不一致可訪問性難倒了。我已經看過其他一些解決方案,並將所有內容設置爲公開,但我仍然堅持如何處理這個問題。C#中字段類型的不一致可訪問性
你能告訴我如何解決這個問題嗎?
public class Level
{
public Tile[,] theGrid;
public Tile[,] TheGrid
{
get { return theGrid; }
set { theGrid = value;}
}
public static Tile[,] BuildGrid(int sizeX, int sizeY)
{
Tile earth = new Tile("Earth", "Bare Earth. Easily traversable.", ' ', true);
//this.createTerrain();
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
theGrid[x, y] = earth;
}
}
return theGrid;
}
而這裏的瓷磚類的簡短版本:
public class Tile
{
//all properties were set to public
public Tile()
{
mineable = false;
symbol = ' ';
traversable = true;
resources = new List<Resource>();
customRules = new List<Rule>();
name = "default tile";
description = "A blank tile";
area = "";
}
public Tile(string tName, string tDescription, char tSymbol, bool tTraversable)
{
resources = new List<Resource>();
customRules = new List<Rule>();
area = "";
symbol = tSymbol;
this.traversable = tTraversable;
this.name = tName;
this.description = tDescription;
mineable = false;
}
public void setArea(string area)
{
this.area = area;
}
}
我會很感激任何幫助,您可以給我這一個。
你能告訴你的'Tile'類的屬性/字段? – BoltClock