【转载】#443 - An Interface Cannot Contain Fields
2014-03-12 16:59
423 查看
An interface can contain methods, properties, events or indexers. It cannot contain fields.
Instead of a field, you can use a property.
Interfaces don't allow fields because they consist of a constract that is a list of methods, whose implementation is provided by a class. Properties are implemented as methods (get and set accessors), so they fit this model. But fields are just data locations, so it doesn't make sense to include them in an interface.
原文地址:#443 - An Interface Cannot Contain Fields
interface IMoo { // Methods void Moo(); // Field not allow - compile-time error string Name; }
Instead of a field, you can use a property.
interface IMoo { // Methods void Moo(); // Name as a property is OK string Name{get; set;} }
Interfaces don't allow fields because they consist of a constract that is a list of methods, whose implementation is provided by a class. Properties are implemented as methods (get and set accessors), so they fit this model. But fields are just data locations, so it doesn't make sense to include them in an interface.
原文地址:#443 - An Interface Cannot Contain Fields
相关文章推荐
- The current type is an interface and cannot be constructed. Are you missing a type mapping?
- 【转载】#445 - Differences Between an Interface and an Abstract Class
- (转载)无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- The type OneInterface cannot be a superinterface of OneInterfaceImpl; a superinterface must be an in
- 【转载】#446 - Deciding Between an Abstract Class and an Interface
- Mongo:You cannot currently mix including and excluding fields. Contact us if this is an issue.
- 【转载】#437 - Access Interface Members through an Interface Variable
- 解决:Cannot push these commits as they contain an email address marked as private on GitHub
- The path "fos_user.from_email.address" cannot contain an empty value, but got null.
- The final local variable xxx cannot be assigned, since it is defined in an enclosing type
- TypeError numpy.float64 object cannot be interpreted as an index
- hexo YAMLException: cannot read a block mapping entry; a multi line key may not be an implicit key a
- An overview of table properties [转载]
- As of ADT 14, resource fields cannot be used as switch cases.
- 无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- Cannot refer to a non-final variable file inside an inner class defined in a different method
- An entity object cannot be referenced by multiple instances of IEntityChangeTracker错误解决
- How to use java dbus to create an Java Interface for dbus interface
- Internet Explorer Cannot Download Office Documents from an IIS Server When Content Expiration Is Set to Expire Immediately
- [org.springframework.web.multipart.MultipartFile]: Specified class is an interface