夜光带你走进C# 接口(十二)擅长的领域

夜光序言:

 

 不要叹息命运的坎坷。

因为大地的不平衡,才有了河流;

因为温度不平衡,才有了万物生长的春夏秋冬;

因为人生的不平衡,才有了我们绚丽的生命。

 

 

 

 

 

 

正文:

 

 

 

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            MyWriteSome Mws = new MyWriteSome();
            Mws.WriteLine();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    interface MyInterface
    {
        //定义方法 输出内容
        void WriteLine();
/*        void ReadKey();*/
    }
    //夜光:继承于接口的类,要实现所有的接口成员
    class MyWriteSome : MyInterface
    {
        public void WriteLine()
        {
            Console.WriteLine("输出文字的接口");
            Console.ReadKey();
        }
    }
}

 

作为过来人

接口并不是很复杂

我们可以理解为一个合同


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

namespace ConsoleApp
{

    //需要注意的:
    //1.接口不可以实例化,什么叫实例化,就是new
    //2.继承于接口的类,要实现所有的接口成员
    //3.接口中,只定义接口成员的声明
    //4.类可以继承多个接口
    interface MyInterface
    {
        //定义方法 输出内容
        void WriteLine();
/*        void ReadKey();*/
    }
    //夜光:继承于接口的类,要实现所有的接口成员
    class MyWriteSome : MyInterface
    {
        public void WriteLine()
        {
            Console.WriteLine("输出文字的接口");
            Console.ReadKey();
        }
    }

    //夜光→其实:接口也是可以继承接口的
    //父类接口
    interface IParentInterface
    {
        void PrintHello();

    }

    //子类接口
    interface IChildInterface 
    {
        void PrintWorld();
    }
    //继承多个接口的类
    //多个接口中的成员都要去实现
    class MyClass : IParentInterface,IChildInterface
    {
        public void PrintHello()
        {

        }
        public void PrintWorld()
        {

        }
    }
    //银行账务,分为很多种
    //一种是普通账户,分为 存款 取款 转账 查询余额 转账有手续费
    //一种是高级账户,分为 存款 取款 转账 查询余额 转账无手续费  免费短信通知
    //把两种账户相同的功能做成一个接口0 存款 取款 转账 查询余额
    //把细分的不同功能做成不同接口 接口1转账有手续费 接口2转账无手续费 接口3免费短信通知





}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值