W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
using System; namespace MyApplication { // 接口 interface IAnimal { void animalSound(); // 接口方法(没有方法体) } // Pig 类“实现”了 IAnimal 接口 class Pig : IAnimal { public void animalSound() { // animalSound() 方法的方法体在这里提供 Console.WriteLine("The pig says: wee wee"); } } class Program { static void Main(string[] args) { Pig myPig = new Pig(); // 创建一个 Pig 对象 myPig.animalSound(); // 调用 animalSound() 方法 } } }