zoukankan      html  css  js  c++  java
  • 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();
            }
        }
    }

    三、接口和抽象类对比

  • 相关阅读:
    ZOJ 1002 Fire Net
    Uva 12889 One-Two-Three
    URAL 1881 Long problem statement
    URAL 1880 Psych Up's Eigenvalues
    URAL 1877 Bicycle Codes
    URAL 1876 Centipede's Morning
    URAL 1873. GOV Chronicles
    Uva 839 Not so Mobile
    Uva 679 Dropping Balls
    An ac a day,keep wa away
  • 原文地址:https://www.cnblogs.com/zytr/p/14737424.html
Copyright © 2011-2022 走看看