索引器允许您按照与数组相同的方式对结构接口进行索引。有关对接口使用索引器的更多信息,请参见接口索引器

要声明类或结构上的索引器,请使用 this 关键字,如下例所示:

 CopyCode image复制代码
public int this[int index]    // Indexer declaration
{
    // get and set accessors
}

Expand 图像备注

Expand 图像示例 1

Expand 图像输出

Expand 图像使用其他值进行索引

Expand 图像示例 2

Expand 图像输出

Expand 图像可靠编程

Expand image请参见