看板 C_Sharp 關於我們 聯絡資訊
各位大大好 小弟最近剛開始學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) { ...... } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.208.113 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1486306694.A.9C0.html
julia28: Location的修飾子可見範圍小於MoveToNewLocation,所以如 02/05 23:15
julia28: 果MoveToNewLocation要用public,參數的型態也必須是publ 02/05 23:15
julia28: ic,這樣的function介面才有意義 02/05 23:15