The type '…' has no constructors defined

前端 未结 6 583
自闭症患者
自闭症患者 2020-11-27 06:07

I\'m noticing the compiler error The type \'...\' has no constructors defined generated when I erroneously attempt to instantiate a particlar class.

6条回答
  •  醉酒成梦
    2020-11-27 06:18

    I believe you would need to make the constructor of the class internal in order to have it throw this exception. I believe you'll also need the class to exist in another assembly.

    namespace MyNamespace
    { 
       class Program
       {
           static void Main(string[] args)
           {
               MyClass mc = new MyClass();
           }
       }
    }
    
    namespace DifferentNamespace
    {
       class MyClass
       {
          internal MyClass()
          {
          }
       }
    }
    

提交回复
热议问题