c#中字段类型的不一致可访问性
本文关键字:访问 不一致 字段 类型 | 更新日期: 2023-09-27 18:15:38
我试图为我的程序做一些简单的类,我被字段类型错误的不一致的可访问性难住了我的Tile[,]类'theGrid'对象。我已经看了一些其他的解决方案,并将我看到的所有内容都设置为public,但我仍然卡住了,不知道该怎么做。
你能告诉我怎么修理这个吗?
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;
}
下面是tile类的缩写:
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;
}
}
静态方法只能访问静态成员。
你需要创建一个新的数组
public static Tile[,] BuildGrid(int sizeX, int sizeY)
{
Tile[,] theGrid = new Tile[sizeX, sizeY];
.... the rest of the code is the same
}
确切的错误消息表明Tile
的可访问性小于public。
但在Tile
的列表中,它是公开的。
- 其他类型之一,
Resource
或Rule
被声明为内部(即没有public
) - 你有另一个
Tile
类 -
public class Tile
的发布代码不正确。 - 错误信息引用不正确