问题描述
internal class Foo
{
public void Fee()
{
Debug.WriteLine("Fee");
}
internal void Fi()
{
Debug.WriteLine("Fi");
}
}
我在想,费()和网络连接()也同样可以访问,因为全班已经是内部的。我俯瞰的东西吗?没有任何理由选择公共或内部在这样的情况下,方法呢?
I'm thinking that Fee() and Fi() are equally accessible since the entire class is already internal. Am I overlooking something? Is there any reason to choose public or internal for the methods in a case like this?
推荐答案
的内部类Foo
声明将覆盖公共无效费的可访问性()
方法,这实际上使得内部。
The internal class Foo
declaration will override the accessibility of the public void Fee()
method, effectively making it internal.
在这种情况下,使用内部相对于公共的方法将具有相同的效果。唯一的原因,我会选择公有方法与在这样的情况下,内部方法将缓解过渡到一个公共类在未来的版本中,你应该选择这样做。
In this case, using internal vs. public on the methods will have the same effect. The only reason I would choose public methods vs. internal methods in a case like this would be to ease transitioning to a public class in a future version, should you choose to do so.
这篇关于公开与一个内部类的内部方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!