嗨我在C#編程方面有點新,而且我有點卡住了。我嘗試過搜索這個網站,但是我沒有找到答案來解決我的問題。我也嘗試改變我的私人到公衆,但沒有奏效。不一致的可訪問性
以下是錯誤消息我得到:
錯誤2可訪問性不一致:參數類型 'exam2.location' 是 比方法 'exam2.Form1.MoveToANewLocation(exam2.location)' 不易進入
這裏是我的代碼部分:
public Form1()
{
IntializeComponent();
CreateObject();
MoveToANewLocation(livingRoom);
}
private void MoveToANewLocation(location newLocation)
{
currentLocation = newLocation;
comboBox1.Items.Clear();
for (int i = 0; i < currentLocation.Exits.Length; i++)
{
comboBox1.Items.Add(currentLocation.Exits[i].Name);
comboBox1.SelectedIndex = 0;
}
textBox1.Text = currentLocation.Description;
if (currentLocation is IHasExteriorDoor)
{
GoThroughTheDoor.Visible = true;
}
else
{
GoThroughTheDoor.Visible = false;
}
}
abstract class location
{
public location(string name)
{
this.name = name;
}
public location[] Exits;
private string name;
public string Name
{
get { return name; }
}
public virtual string Description
{
get {
string description = "You're standing in the" + name +
". You see exits to the following places: ";
for (int i = 0; i < Exits.Length; i++)
{
description += " " + Exits[i].Name;
if (i != Exits.Length - 1)
description += ",";
}
description += ",";
return description;
}
}
}
什麼是地點類標記爲? – BradleyDotNET
對於遲到的回覆,我很抱歉,自從我參加該計劃以來,我一直沒有上網。我將位置類標記爲「抽象類位置」。在所有的課程中,我公開發布了自己的代碼,當我將它們設爲私有時,我創建了一個'get'訪問器,以便能夠訪問另一個類中的私有代碼。非常感謝回覆 – Hannah