日期:2014-05-17  浏览次数:21016 次

c#中interface的使用的小例子

今天,做个一个interface使用的例子,大家可以在vs下跑跑,对初学者还是很有益处的。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            Dog test = new Dog();
            test.method();
        }
    }
    public interface facetest
    {

//注意到前面不能加修饰符,否则过不去。
        string identitya { get;}//提供了一个属性,虽然没有set方法,但是重写时可以写。
        void methodbggg();
    }
    public class Dog:facetest
    {
        public string Abc = "ffff";
        public void method()
        {
            MessageBox.Show("字符是"+Abc);
        }
        public  void methodbggg()
        {
            string testdd = "33";
        }
        public string identitya
        {
            get
            {
                return "44";
            }
            set
            {
                value = Abc;
            }
        }
    }
  
}