C# 接口练习
#define debug using System; using System.Collections; namespace ConsoleApp1 { interface IAnimal { int Age { get; set; } void Say(); } class Program { static void Main(string[] args) { Dog d = new Dog(); d.Age = 10; d.Say(); Console.ReadKey(); } } class Dog:IAnimal { public int Age { get; set; } public void Say() { Console.WriteLine(this.Age); } } }
总结:
接口中不能有字段,可以有属性,需要设置get;set 访问器