[英]Why I cannot call a parameterized constructor with generics if I specify the base class
[英]Why I cannot call the base class Constructor?
我有一個類是System.Drawing.Bitmap
的子級。 我正在嘗試調用其構造函數,但在調用基類構造函數時遇到問題。
更具體地說,我想調用該特定的構造函數:
Bitmap(String)
:從指定的文件初始化Bitmap類的新實例。
我認為問題在於它無法識別我的類是從Bitmap
類繼承的,因為錯誤是針對Object類的 。
無論如何,這是我的課:
class MyBitmap : Bitmap
{
private String photographer, description, title;
public String Photographer
{
get
{
return this.photographer;
}
}
public String Description
{
get
{
return this.description;
}
}
public String Title
{
get
{
return this.title;
}
}
public MyBitmap(String filePath, String title, String description, String photographer) : base(filePath)
{
this.title = title;
this.description = description;
this.photographer = photographer;
}
}
錯誤的原因是System.Drawing.Bitmap
是一個密封的類。
因此, 根本不允許您從Bitmap
繼承。 檢查您的編譯器錯誤消息,您應該已經收到錯誤CS0509
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.