例如:

 

class Container
{
    class Nested
    {
        Nested() { }
    }
}

 

Nested 对外部类型是不可访问的,但可以设置为 public,如下所示:

 

class Container
{
    public class Nested
    {
        Nested() { }
    }
}

 

例如:

public class Container
{
    public class Nested
    {
        private Container parent;

        public Nested()
        {
        }
        public Nested(Container parent)
        {
            this.parent = parent;
        }
    }
}

嵌套类型可访问包含类型的私有成员和受保护的成员(包括所有继承的私有成员或受保护的成员)。

这是用来创建嵌套类的新实例的名称,如下所示:

 

Container.Nested nest = new Container.Nested();

 

相关文章:

  • 2021-11-07
  • 2021-08-24
  • 2022-12-23
  • 2021-09-13
  • 2021-11-15
  • 2021-08-01
  • 2022-01-20
猜你喜欢
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案