简体   繁体   English

class不会让我创建一个新对象

[英]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来继承PagerLinkPagerLink 。就这样做:

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.

相关问题 Visual Studio 2013不允许我为网站项目在文件后面创建代码 - Visual Studio 2013 won't let me create code behind file for Web Site project VWD Express不允许我添加一张桌子 - VWD Express won't let me add one table 为什么VS 2008 SP1不允许我编辑global.asax? - Why won't VS 2008 SP1 let me edit global.asax? 转发器不会让我访问按钮,下拉菜单等控件 - Repeater won't let me access controls like buttons, dropdown, etc ASP.NET 的框架 javascript 不允许我渲染原始 HTML IFRAME - ASP.NET's framework javascript won't let me render a raw HTML IFRAME 为什么LINQ to Entities不让我仅初始化实体的某些属性? - Why LINQ to Entities won't let me initialize just some properties of an Entity? ASP.NET 配置工具不会让我配置“安全”设置 - ASP.NET configuration tool won't let me configure “Security” settings 将VS2012项目升级到VS2013网站,它不会让我指定IIS端口 - Upgrade VS2012 project to VS2013 web site and it won't let me specify IIS port 为什么不会在类中注入新对象 - Why Won't Ninject New Up Objects In A Class Asp.Net网站不允许我添加参考类库。 已经存在 - Asp.Net website won't allow me to add reference class library. Already exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM