我是C#的新手,並嘗試使用它。繼承來自子類的超類屬性
我有一個超級Form
與屬性FormID
。 Form
由其他4個子類繼承。
Form-> DeployForm -> SystemOut
and Form_> Colection -> SystemIn
。
如何從子類訪問屬性FormID
? (DeployForm
,SystemOutColection
,Collectiom
和SystemIn
?)
// Superclass - Form.
public class Form
{
private int _FormID;
private string _UserName;
private string _ComputerName;
private string _AssetTag;
private string _Department;
private string _Status;
// Below are the associations I linked
// to other classes that don't require attribute FormID.
private FormCategory _differentiateBy;
private CheckList _referencesToChecklist;
private Staff _referencesToStaff;
public Form()
{
_differentiateBy = new FormCategory();
_referencesToChecklist = new CheckList();
_referencesToStaff = new Staff();
}
public int FormID
{
get { return _FormID; }
set { _FormID = value; }
}
}
// Sub Class - DeploymentForm
public class DeploymentForm : Form
{
private DateTime _DeployDate;
private int _DeployBy;
private DateTime _SetupDate;
private int _SetupBy;
public DeploymentForm()
{
}
public DateTime DeployDate
{
get { return _DeployDate; }
set { _DeployDate = value; }
}
public int DeployBy
{
get { return _DeployBy; }
set { _DeployBy = value; }
}
public DateTime SetupDate
{
get { return _SetupDate; }
set { _SetupDate = value; }
}
public int SetupBy
{
get { return _SetupBy; }
set { _SetupBy = value; }
}
}
// etc...
僅在派生類中使用'this.FormID'或'base.FormID'。 –
由於你是新人,我冒昧地讓你的問題可讀。這將更有可能做出很好的回答。如果我明確地改變了意思,我很抱歉。請編輯避免含糊不清的問題。 – Jodrell
謝謝@Jorell,謝謝你幫我重述這個問題。 – AlphaRomeo69