类型'...'没有定义的构造函数 [英] The type '...' has no constructors defined

查看:266
本文介绍了类型'...'没有定义的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到的编译器错误的类型'...'没有定义的构造函数当我尝试错误实例化一个particlar类生成。

这使我不知道我怎么会去写我自己的类时,有人试图将它实例化,将precipitate此消息。

所以,code以下,有什么我需要做的 MyClass的

 命名空间了myNameSpace
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            MyClass的MC =新MyClass的();
        }
    }    MyClass类
    {
        我的课()
        {
        }
    }
}


解决方案

此错误( CS0143 )发生在类只定义了一个内部构造,并尝试从另一个组件进行实例化

 公共类MyClass的
{
    内部MyClass的()
    {
    }
}

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

It lead me to wonder how I would go about writing my own class that would precipitate this message when someone attempted to instantiate it.

So the code below, what do I need to do to MyClass?

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

    class MyClass
    {
        MyClass()
        {
        }
    }
}

解决方案

This error (CS0143) occurs if the class only defines an internal constructor and you try to instantiate it from another assembly.

public class MyClass
{
    internal MyClass()
    {
    }
}

这篇关于类型'...'没有定义的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆