父级不包含采用 0 个参数的构造函数 [英] Parent does not contain a constructor that takes 0 arguments
本文介绍了父级不包含采用 0 个参数的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码是
namespace classlibrary
{
public class numerictext : EditText
{
//My code
}
当我尝试继承类库中的编辑文本控件时,出现错误:父级不包含采用 0 个参数的构造函数.我理解问题是 Parent 没有带有 0 个参数的构造函数.但是如何继承类库中的控件?
When I try to inherit a edit text control in a class library, I'm getting the error: Parent does not contain a constructor that takes 0 arguments. I understand the problem is that Parent has no constructor with 0 arguments. But how to inherit a control in a class library?
推荐答案
您需要调用派生类中的基构造函数之一.假设您使用的是 Android EditText
小部件:
You need to call one of the base constructors in your derived class. Assuming you are using the Android EditText
widget:
public class numerictext : EditText
{
public numerictext(Context context) : base(context)
//^^^^^^^^^^^^^^^
//Note how we are now calling the base constructure
{
//empty or you can add your own code
}
public numerictext(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
//etc
}
这篇关于父级不包含采用 0 个参数的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文