程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Part 30 to 31 Talking about Interfaces in c#,

Part 30 to 31 Talking about Interfaces in c#,

編輯:C#入門知識

Part 30 to 31 Talking about Interfaces in c#,


Part 30 Interfaces in c#

We create interfaces using interface keyword. just like classes interfaces also contains properties, methods, delegates or events, but only declarations and no implementations.

It is a compile time error to privide implementations for any interface member.

Interface members are public by default, and they don't allow explicit(顯式) access modifiers.

Interfaces cannot contain fields.(接口不可以包含字段)

If a class or struct inherits from an interface , it must provide implementation for all interface members. Otherwise, we get a compiler error.

A class or a struct can inherit from more than one interface at the same time, but where as, a class cannot inherit from more than oncee class at the same thime.

Interfaces can inherit from other interfaces. A class that inherits this interface must provide implementation for all interface members in the entire interface inheritance chain(一系列)

We cannot create an instance of an interface, but an interface reference variable can point to a derived class object.(接口不可以實例化,可是接口的引用可以指向子類,例如:IA a = new IA(); 這個是錯的,可是如果類A繼承了接口IA,那麼這樣是可以的:IA a = new A();

Part 31 - C# Tutorial - Explicit interfaces implementation

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved