- 要点:
public — 公用的,所有类以及命名空间均可使用。
protected — 只能在当前命名空间中使用。
private — 私有的,只能在类里面使用。
另外: 无修饰符默认为 protected .
常用修饰符有2个,分别是 public 和 private .、
至于protected , 初学者暂时可以只做一个了解。
-
示例代码:
namespace ABC //命名空间ABC
{
public class test
{
public string test; //公用,所有类(class)以及命名空间(namespace)均可使用
protected int a; //只能在命名空间内使用
int b; //这里需要注意,无修饰符,默认为protected!
private count; //私有的,只有在这个class里面才能使用,其他class均无法使用!
public test(string test)
{
this.test = test;
}
}
}
namespace cda //命名空间cda
{
public class program
{
public static void Main(String[] args)
{
test zmsky = new test()
}
}
}
路过。。学习一下。