Chapter 15: Using Indexers


Chapter 15

Using Indexers

After completing this chapter, you will be able to:

  • Encapsulate logical array-like declarations by using indexers.

  • Control read access to indexers by declaring get accessors.

  • Control write access to indexers by declaring set accessors.

  • Create interfaces that declare indexers.

  • Implement indexers in structs and classes that inherit from interfaces.

The previous chapter described how to use and implement properties as a means of providing controlled access to the fields in a class. Properties are useful for mirroring fields that contain a single value. However, indexers are invaluable if you want to provide access to items that contain multiple values, by using a natural and familiar syntax.




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net