1. 介面成員只有宣告而不能有實作.

2. 介面成員預設是public,所以不能給存取控制修飾詞.

3. 介面是不能包含欄位fields(大陸用語叫字段).

4. 如果class或struct繼承了interface,就必須實作該interface的所有成員.

5. class或struct能同時繼承多個interface

6. interface也能繼承interface,如果class或struct繼承了interface,而這個interface有繼承其他的interface,該class或struct必須實作出所有繼承鏈中所有interface的成員.

7. interface是無法被實例化的.

8. 如果要實例化可以由繼承的class物件轉型成interface.(如下例)

interface ImyInterface
{
    void print();
}

public class myClass : ImyInterface
{
    public void print()
    {
        Console.WriteLine("print method");
    }
}

public class program
{
    static void Main()
    {
        ImyInterface i1 = new myClass();
        i1.print();
        Console.ReadKey();
    }
}

arrow
arrow
    文章標籤
    c# interface using attentions
    全站熱搜

    痞客興 發表在 痞客邦 留言(0) 人氣()