[问题] 深入浅出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