16、接口

一、接口简介

二、接口的规则

  

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

namespace WindowsFormsApplication1
{
   public interface Ibook
    {
        string B_name { get; set; }
        void InsertToData();
    }
    public interface IZbook:Ibook
    {
        double B_Price { get; set; }
    }
    public class book : IZbook
    {
        public string B_name
        {
            get;

            set;
            
        }

        public double B_Price
        {
            get;
            set;
        }

        public void InsertToData()
        {
            string info = "书名:" + B_name + "价格:" + B_Price.ToString();
            MessageBox.Show(info);
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            double price = Convert.ToDouble(textBox2.Text);
            IZbook b = new book();
            b.B_name = name;
            b.B_Price = price;
            b.InsertToData();
        }
    }
}

三、接口和抽象类对比

原文地址:https://www.cnblogs.com/zytr/p/14737424.html