溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#怎么繼承InterfaceInheritance.cs接口

發布時間:2022-04-01 14:08:13 來源:億速云 閱讀:235 作者:iii 欄目:編程語言

本文小編為大家詳細介紹“C#怎么繼承InterfaceInheritance.cs接口”,內容詳細,步驟清晰,細節處理妥當,希望這篇“C#怎么繼承InterfaceInheritance.cs接口”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

接口繼承: InterfaceInheritance.cs

以下實例定義了兩個接口 IMyInterface 和 IParentInterface。

如果一個接口繼承其他接口,那么實現類或結構就需要實現所有接口的成員。

以下實例 IMyInterface 繼承了 IParentInterface 接口,因此接口實現類必須實現 MethodToImplement() 和 ParentInterfaceMethod() 方法:

using System;

interface IParentInterface
{
    void ParentInterfaceMethod();
}

interface IMyInterface : IParentInterface
{
    void MethodToImplement();
}

class InterfaceImplementer : IMyInterface
{
    static void Main()
    {
        InterfaceImplementer iImp = new InterfaceImplementer();
        iImp.MethodToImplement();
        iImp.ParentInterfaceMethod();
    }

    public void MethodToImplement()
    {
        Console.WriteLine("MethodToImplement() called.");
    }

    public void ParentInterfaceMethod()
    {
        Console.WriteLine("ParentInterfaceMethod() called.");
    }
}

實例輸出結果為:

MethodToImplement() called.
ParentInterfaceMethod() called.

讀到這里,這篇“C#怎么繼承InterfaceInheritance.cs接口”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女