开发者

Interface: Why can i use a property but not a field? [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_如何学Go

Possible Duplicate:

Why can't C# interfaces contain fields?

Why can i use a property but not a field in an interface? I don't understand what would be different in the backend (sure one is more like a method but why does that matter) or any reasoning to exclude fields from interfaces.


Interfaces consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.

An interface has the following properties:

An interface is like an abstract base class: any non-abstract type that implements the interface must implement all its members.

An interface cannot be instantiated directly.

Interfaces can contain events, indexers, methods, and properties.

Interfaces contain no implementation of methods.

Classes and structs can implement more than one interface.

An interface itself can inherit from multiple interfaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜