簡單說來
聲明方法如下(與屬性相似)
public type this [int index]
{
get
{
//
}
set
{
//
}
}
用例子簡單說明
using System
static void Main(string[] args)
{
//調用IntBits
IntBits bits = new IntBits(
//獲得索引
bool peek = bits[
Console
bits[
Console
Console
}
struct IntBits
{
private int bits;
public IntBits(int initialBitValue)
{
bits = initialBitValue;
Console
}
//定義索引器
//索引器的
public bool this [int index]
{
get
{
return true;
}
set
{
if (value)
{
bits =
}
}
}
[
From:http://tw.wingwit.com/Article/program/net/201311/15301.html