使用c#中的代码示例覆盖抽象类中的概念

时间:2016-04-08 18:44:17

标签: oop polymorphism abstract-class override

我正在尝试从名为RepositoryVoucher.cs的主类访问我的RepositoryJournalVoucher.cs类的对象,但我无法访问或创建实例,不知道原因。

抽象类RepositoryUniversalAccounts.cs

namespace eCartDynamic.RepositoryApplication
{
    public abstract class RepositoryUniversalAccounts
    {
        public string AccountCode { get; set; }
        public abstract string PostVoucher();
    }
}

RepositoryCashVoucher.cs

namespace eCartDynamic.RepositoryApplication
{
    public class RepositoryCashVoucher : RepositoryUniversalAccounts
    {
        public override string PostVoucher()
        {
            AccountCode = "16-01-001-01-000001-CV";
            return "CV Posted Sucessfully";
        }
    }
}

RepositoryJournalVoucher.cs

namespace eCartDynamic.RepositoryApplication
{
    public class RepositoryJournalVoucher : RepositoryUniversalAccounts
    {
        public override string PostVoucher()
        {
            AccountCode = "16-01-001-01-000001-JV";
            return "JV Posted Sucessfully";
        }
    }
}

主类。 RepositoryVoucher.cs

namespace eCartDynamic.RepositoryApplication
{
    public class RepositoryVoucher
    {
        RepositoryUniversalAccounts abc = new RepositoryJournalVoucher();

    }
}

在我的RepositoryVoucher.cs类中,我无法创建类似的对象:

RepositoryUniversalAccounts abc = new RepositoryJournalVoucher();    RepositoryJournalVoucherabc obj = new RepositoryJournalVoucher();

0 个答案:

没有答案