Chapter 15 Quick Reference


Chapter 15 Quick Reference

To

Do this

Create an indexer for a class or struct

Declare the type of the indexer, followed by the keyword this, and then the indexer arguments between square brackets. The body of the indexer can contain a get and/or set accessor. For example:

struct RawInt {     ...     public bool this [ int index  ]     {         get { ... }         set { ... }     }     ... }

Define an indexer in an interface

Define an indexer with the get and/or set keywords. For example:

interface IRawInt {     bool this [ int index ]  get;  set; } }

Implement an interface indexer in a class or struct

In the class or struct that implements the interface, define the indexer and implement the accessors. For example:

struct RawInt : IRawInt {     ...     public bool this [ int index  ]     {         get { ... }         set { ... }     }     ... }

Implement an interface indexer by using explicit interface implementation in a class or struct

In the class or struct that implements the interface, explicitly name the interface, but do not specify the indexer accessibility. For example:

struct RawInt : IRawInt {     ...     bool IRawInt.this [ int index  ]     {         get { ... }         set { ... }     }     ... }




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