[英]Nested classes in c#
Sorry I'm kinda new to c# how would I make a class where I can access it like this: Myclass.subclass.method(); 抱歉,我是C#的新手,我将如何制作一个可以像这样访问它的类:Myclass.subclass.method();
This is what I have now: 这就是我现在拥有的:
namespace zzcore
{
class myclass
{
class subclass
{
public static void method() { }
}
}
}
What happens here is that a nested class without a visibility modifier is implicitly private
. 这里发生的是没有可见性修饰符的嵌套类是隐式private
。 In this context, private
means that only the parent class can see it. 在这种情况下, private
意味着只有父类才能看到它。
Declare both classes as public
and you will be able to call myclass.subclass.method();
将两个类都声明为public
,您将可以调用myclass.subclass.method();
namespace zzcore
{
public class myclass
{
public class subclass
{
public static void method() { }
}
}
}
Working example: http://ideone.com/tJVKJ 工作示例: http : //ideone.com/tJVKJ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.