为什么可以在C#中为抽象类编写构造函数?
据我所知,我们无法实例化一个抽象类..那么它的用途是什么?
你无法实例化这个类,对吧?
我在WPF中编写了这段代码:
System.Windows.Controls.Panel Panel1 = null;
Panel1 = new System.Windows.Controls.Panel();
Run Code Online (Sandbox Code Playgroud)
但是它说:
Error1 Cannot create an instance of the abstract class or interface 'System.Windows.Controls.Panel'
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?任何人都可以回答我的问题
我Cannot create an instance of the abstract class or interface在C#教程中收到错误.
它在这条线上失败了: result = new Account(nameText, addressText, balance);
这是我的班级:
public abstract class Account : IAccount
{
//---------------------------------------------------------------
// Constructor
//---------------------------------------------------------------
public Account(string inName, string inAddress, decimal inBalance)
{
name = inName;
address = inAddress;
balance = inBalance;
}
public Account(string inName, string inAddress) :
this(inName, inAddress, 0) // 'this ties this alternate constructor back to the original constructor (directly above)
{
}
public Account(string inName) : // 'this ties …Run Code Online (Sandbox Code Playgroud)