[100分]请讲述接口的属性,概念,应用!谢谢,立即给分

解决方案 »

  1.   

    请看:
    http://blog.csdn.net/chengking/archive/2005/11/16/530684.aspx
      

  2.   

    C# 程序员参考   interface请参见
    C# 关键字 | 引用类型 | 属性 | 索引器 | C. 语法 | 显式接口实现教程 | class | struct
    一个接口定义一个协定。实现接口的类或结构必须遵守其协定。声明采用下列形式:[attributes] [modifiers] interface identifier [:base-list] {interface-body}[;]
    其中: attributes(可选) 
    附加的声明性信息。有关属性和属性类的更多信息,请参见 17. 属性。 
    modifiers(可选) 
    允许使用的修饰符有 new 和四个访问修饰符。 
    identifier 
    接口名称。 
    base-list(可选) 
    包含一个或多个显式基接口的列表,接口间由逗号分隔。 
    interface-body 
    对接口成员的声明。 
    备注
    接口可以是命名空间或类的成员,并且可以包含下列成员的签名: 方法 
    属性 
    索引器 
    事件 
    一个接口可从一个或多个基接口继承。在下例中,接口 IMyInterface 从两个基接口 IBase1 和 IBase2 继承:interface IMyInterface: IBase1, IBase2
    {
       void MethodA();
       void MethodB();
    }
    接口可以由类和结构实现。实现的接口的标识符出现在类的基列表中。例如:class Class1: Iface1, Iface2
    {
       // class members
    }
    类的基列表同时包含基类和接口时,列表中首先出现的是基类。例如:class ClassA: BaseClass, Iface1, Iface2 
    {
       // class members
    }
    有关接口的更多信息,请参见接口。有关属性和索引器的更多信息,请参见属性声明和索引器声明。示例
    下例说明了接口的实现。在此例中,接口 IPoint 包含属性声明,后者负责设置和获取字段的值。MyPoint 类包含属性实现。// keyword_interface.cs
    // Interface implementation
    using System;
    interface IPoint 
    {
       // Property signatures:
       int x 
       {
          get; 
          set; 
       }   int y 
       {
          get; 
          set; 
       }
    }class MyPoint : IPoint 
    {
       // Fields:
       private int myX;
       private int myY;   // Constructor:
       public MyPoint(int x, int y) 
       {
          myX = x;
          myY = y;
       }   // Property implementation:
       public int x 
       {
          get 
          {
             return myX;
          }      set 
          {
             myX = value; 
          }
       }   public int y 
       {
          get 
          {
             return myY; 
          }
          set 
          {
             myY = value; 
          }
       }
    }class MainClass 
    {
       private static void PrintPoint(IPoint p) 
       {
          Console.WriteLine("x={0}, y={1}", p.x, p.y);
       }   public static void Main() 
       {
          MyPoint p = new MyPoint(2,3);
          Console.Write("My Point: ");
          PrintPoint(p);
       }
    }
    输出
    My Point: x=2, y=3