簡體   English   中英

為什么我不能調用基類的構造方法?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM