logo
  • 教程列表
  • SO官方文檔
  • 繼承
    • 繼承。建構函式呼叫序列
    • 繼承自基類
    • 繼承自類並實現介面
    • 從類繼承並實現多個介面
    • 測試和導航繼承
    • 擴充套件抽象基類
    • 子類中的建構函式
    • 繼承反模式
    • 繼承方法
    • 具有遞迴型別規範的基類
  1. StackOverflow 文件
  2. C# Language 教程
  3. 繼承
  4. 繼承自類並實現介面

繼承自類並實現介面

Created: November-22, 2018

public class Animal 
{
    public string Name { get; set; }
}

public interface INoiseMaker
{
    string MakeNoise();
}

//Note that in C#, the base class name must come before the interface names
public class Cat : Animal, INoiseMaker
{
    public Cat() 
    {
        Name = "Cat";
    }

    public string MakeNoise()
    {
        return "Nyan";
    }
}
  • 從類繼承並實現多個介面
  • 繼承自基類

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明