[問題] 深入淺出C#第七章大習題 public問題

作者: luck777 (notebook)   2017-02-05 22:58:12
各位大大好
小弟最近剛開始學C#
版上有很多大大推薦"深入淺出C#"這本書
所以就從這書開始學C#
目前在第七章最後的大習題遇到一個問題
自己在編寫的時候
將以下這段程式碼中MoveToANewLocation 修飾子寫成 public
出現了錯誤訊息:"Inconsistent accessibilty:parameter type'Location' is less accessible than
method 'Form1.MoveToANewLocation (Location)'"
自己研究這句話很久還是不太了解
但將修飾子改為private後錯誤訊息就不見了
由於很想知道錯誤原因
但自己實在看不出來
所以來版上
希望有大大願意回答小弟的問題
請各位指教了
namespace Chapter7_House_version1
{
public partial class Form1 : Form
{
......
public Form1()
{
......
}
public void CreateObjects()
{
......
}
public void MoveToANewLocation (Location newLocation)
{
currentLocation = newLocation;
exits.Items.Clear();
for (int i = 0; i < currentLocation.Exits.Length; i++)
{
exits.Items.Add(currentLocation.Exits[i].Name);
}
exits.SelectedIndex = 0;
description.Text = currentLocation.Description;
if(currentLocation is IHasExteriorDoor)
{
goThroughTheDoor.Visible = true;
}else
{
goThroughTheDoor.Visible = false;
}
}
private void goHere_Click(object sender, EventArgs e)
{
......
}
private void goThroughTheDoor_Click(object sender, EventArgs e)
{
......
}
}
}
作者: julia28 (堅強?!)   2017-02-05 23:15:00
Location的修飾子可見範圍小於MoveToNewLocation,所以如果MoveToNewLocation要用public,參數的型態也必須是public,這樣的function介面才有意義

Links booklink

Contact Us: admin [ a t ] ucptt.com