索引函数的使用三
using System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary6
{
struct IntBits
{
private int bits;
public IntBits(int initialBitValue)
{
bits = initialBitValue;
}
public bool this[int index]
{
get
{
return (bits & (1 << index)) != 0;//不等于0返回的就是true,等于0返回的就是false。
}
set
{
if (value)//如果value为true,就开启比特,否则把它关闭。
bits |= (1 << index);
else
bits &= ~(1 << index);
}
}
}
}


浙公网安备 33010602011771号