文件名称:As you can see,indexers behave much like a custom collection supporting the IEnumeratorand
文件大小:7.99MB
文件格式:PDF
更新时间:2013-08-23 07:26:04
As you can see,indexers behave
As you can see,indexers behave much like a custom collection supporting the IEnumeratorand IEnumerableinterfaces in that they provide access to a container’s subitems. The major difference ofcourse is that rather than accessing the contents using the foreachconstruct, you are able to manipulate the internal collection of sub-objects just like a standardarray. Now for the big question: How do you configure the PeopleCollectionclass (or any class/ structure) to support this functionality? An indexer is represented as a slightly mangled C# property. Inits simplest form, an indexer is created using the this[]syntax. Hereis the required update for the PeopleCollectionclass: