作者dedek (我要快樂起來)
看板C_Sharp
標題[問題] 有關virtual & override
時間Sun Mar 28 23:30:34 2010
請問如果子類別繼承了父類別,但是父類別無法修改成virtual
要如何才能使用override改寫父類別的成員呢?
下面程式碼是父類別的成員,要如何override才能 set 這個filename?
public string FileName
{
get
{
HttpPostedFile postedFile = this.PostedFile;
string str = string.Empty;
if (postedFile == null)
{
return str;
}
string fileName = postedFile.FileName;
try
{
return Path.GetFileName(fileName);
}
catch
{
return fileName;
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.37.93.238
推 F23ko:this.PostedFile 是 private嗎? 囧..... 03/29 01:21
推 petrushka:試著用new這個關鍵詞吧,但記得不要用父介面指向子物件 03/29 15:56
→ petrushka:可以參考5046篇相關的應用說明 03/29 15:56
→ dedek:謝謝P大~還是有疑問,我在您之前發表的那篇文章有提書問題 03/31 21:06