我有这个类和构造函数
public class BillOutcomeClass
{
public string LargeMessage { get; set; }
public string MobileMessage { get; set; }
public string Value { get; set; }
public BillOutcomeClass(string acctNumber, HttpContext currentContext)
{
Customer customer = CustomerSecurity.GetCustomer(currentContext);
Account acct = customer.GetAccountForTransaction(acctNumber);
}
}
我需要能够在PastDue类中使用Account
和Customer
实例。必须能够在继承的类中访问这些类。
这是继承的类。
public class PastDue : BillOutcomeClass
{
public PastDue (string acctNumber, HttpContext currentContext) : base (acctNumber, currentContext)
{
/// I need to be able to access customer.prop, and acct.prop from the base class
}
}
答案 0 :(得分:7)
在我看来,您只需要一些protected
属性:
public class BillOutcomeClass
{
public string LargeMessage { get; set; }
public string MobileMessage { get; set; }
public string Value { get; set; }
protected Customer Cust { get; set; }
protected Account Acct { get; set; }
public BillOutcomeClass(string acctNumber, HttpContext currentContext)
{
this.Cust = CustomerSecurity.GetCustomer(currentContext);
this.Acct = customer.GetAccountForTransaction(acctNumber);
}
}