[英]class won't let me create a new object
Hi I'm unable to create a new object that is a subclass I think that's what you call it it saying virtual isn't allowed what must I do to correct this here is my code. 嗨,我无法创建一个新的对象,这是一个子类我认为这就是你所说的它说虚拟是不允许我必须做的,这里纠正这里是我的代码。
public class PagerBuilder {
private virtual class PagerLink
{
public string Title { get; set;}
public int PageNo { get; set; }
public string Class { get;set;}
}
private readonly List<PagerLink> _pagerLinks = new List<PagerLink>();
private readonly string _urlTemplate;
public PagerBuilder(string urlTemplate)
{
_urlTemplate = urlTemplate;
}
public string PagerClass { get;set;}
public void AddPage(string title, int pageNo)
{
AddPage(title, pageNo, string.Empty);
}
public void AddPage(string title, int pageNo, string itemClass)
{
PagerLink link = new PagerLink();
}
}
First, I would move PagerLink
outside of the PagerBuilder
class and define it separately (in a new file as well). 首先,我会提出PagerLink
的外PagerBuilder
类,并分别将其定义(在一个新的文件以及)。
Second, you don't need virtual to subclass PagerLink
(It's not even valid, in fact). 其次,你不需要虚拟子类化PagerLink
(事实上它甚至都不是有效的)。 If you want it to be abstract, use the abstract
keyword instead, but this code won't compile (at PagerLink link = new PagerLink()
until you define a concrete implementation of PagerLink
. You don't need to use abstract
to inherit from PagerLink
, though. Just do this: 如果你想要它是抽象的,那么使用abstract
关键字,但是这个代码将不会编译(在PagerLink link = new PagerLink()
直到你定义了一个具体的PagerLink
实现。你不需要使用abstract
来继承PagerLink
, PagerLink
。就这样做:
public class CustomPagerLink: PagerLink
{
//Subclass implementation
}
You want to remove virtual
from your class definition. 您想要从类定义中删除virtual
。
private class PagerLink
{
public string Title { get; set;}
public int PageNo { get; set; }
public string Class { get;set;}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.