覆盖c#中的基本受保护属性

Jam*_*ith 0 c# oop inheritance

轻微的新手问题.

我有一个支付基类.除了额外的额外内容,所有人都拥有相同的属性.其中一个属性是postUrl.在基础中,这是空的,但在子类中,每个类都有自己的URL.不应该允许从类外部访问它并且它已修复且不应更改.我如何在儿童班中覆盖房产?

例如

class paymentBase
{
    public int transactionId {get;set;}
    public string item {get;set;}
    protected virtual postUrl = String.empty; // can't be accessed from outside inheritance / public / protected?

    public void payme();
}

class paymentGateWayNamePayment : paymentBase
{
    protected override postUrl { 
        get { return "http://myurl.com/payme"; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

提前致谢

Ale*_*lex 7

如果你创建postUrl一个真正的虚拟财产,你应该能够完成它,如下所示:

class paymentBase
{
    public int transactionId {get;set;}
    public string item {get;set;}
    protected virtual postUrl { get { return String.Empty; }}

    public void payme();
}

class paymentGateWayNamePayment : paymentBase
{
    protected override postUrl {get { return "http://myurl.com/payme"; } }
}
Run Code Online (Sandbox Code Playgroud)