- Because properties are implemented with methods, adding multithreaded support is easier. You can enhance the implementation of the get and set accessors to provide synchronized access to the data:
|
|
|
|
Indexers can be virtual or abstract, can be declared in interfaces, and can be read-only or read-write.
Indexers can use noninteger parameters to define maps and dictionaries
|
In keeping with the multidimensional arrays in C#, you can create multidimensional indexers, with similar or different types on each axis:
|
Notice that all indexers are declared with the this keyword. You cannot name an indexer in C#. Therefore, every different indexer in a type must have distinct parameter lists to avoid ambiguity.
P roperty accessors should live up to users' expectationsGet accessors should not have observable side effects. Set accessors do modify the state, and users should be able to see those changes. It should not have performance characteristics that are significantly different than a simple data access. Property accessors should not perform lengthy computations, or make cross-application calls (such as perform database queries), or do other lengthy operations that would be inconsistent with your users’expectations for a property accessor.
转载于:https://blog.51cto.com/nemobao/839479