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 访问器

posted @ 2019-05-04 21:30  liliyou  阅读(313)  评论(0编辑  收藏  举报