码迷,mamicode.com
首页 > 其他好文 > 详细

接口练习代码

时间:2017-06-25 21:47:26      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:ble   ane   接口   names   cat   linq   new   name   logs   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           
            Console.WriteLine("================接口练习============================");
            plane pl = new plane();
            pl[0] = "战斗机";
            Console.WriteLine(pl[0]);
            Console.WriteLine(pl.Name);
            pl.fly(8);
            pl.Speed = 200;
            Console.WriteLine(pl.Speed);


            Console.ReadKey();
        }
  

        //接口
        #region flyable接口

      
        public interface flyable
        {
            void fly(int x);

            string this[int x]
            {
                get;
                set;
            }

            int Speed { get; set; }
        }
        #endregion
        #region Plane类


        class plane :flyable
        {
            int speed;
            string name;
            public void fly (int x)
            {
                Console.WriteLine("飞行速度为:"+x);
            }

            public  string this[int x ]
            {
                set
                {
                    Name = value;
                }
                get
                {
                    return Name+"的序号为:"+x;
                }
            }
            public int Speed
            {
                get
                {
                    return speed;
                }
                set
                {
                    speed = value;
                }

            }

            public string Name
            {
                get
                {
                    return name;
                }

                set
                {
                    name = value;
                }
            }
        }
        #endregion

}

注意 :索引器前面要加 public,要不 检查代码认为没有实现该接口

接口练习代码

标签:ble   ane   接口   names   cat   linq   new   name   logs   

原文地址:http://www.cnblogs.com/ilrc/p/7078068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!