Accessing a Private Constructor from Outside the Class in C#

前端 未结 8 1592
梦如初夏
梦如初夏 2020-12-30 21:52

If I define a class with a private default constructor and a public constructor that has parameters, how can I access the private constructor?

public class Bo         


        
8条回答
  •  有刺的猬
    2020-12-30 22:09

    The method Bobby is still in a different class, called Fred. That is why you can't access the prive constructor of the Bob class. What you are trying to do is not possible with attached methods. Even if they can be attached on another class they are still declared outside that class and follow the usual scope/access rules.

提交回复
热议问题