Regarding OOPS & Private class

2019-08-14 14:37发布

if my class is private and constructor is public then what will happen. can i create a instance of that class or other class can i extend? i just need to know why and when people create a private class with public ctor?

the code like

private class LazyResource
{
    SomeBigResource _heavyObject = null;

    public SomeBigResource LazyLoad
    {
        get
        {
            if (_heavyObject == null)
                _heavyObject = new SomeBigResource();
            return _heavyObject;
        }
    }
}

plzz guide me thanks

标签: c# oop
1条回答
手持菜刀,她持情操
2楼-- · 2019-08-14 14:55

You can't create a non-nested private class in C#.

This is almost certainly a nested class, in which case only the containing type can instantiate an instance of it. And if LazyResource only had a private constructor then nothing would be able to instantiate it (except for a static member of LazyResource itself).

查看更多
登录 后发表回答