草随原

骏马

导航

索引函数的使用三

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);
          }

      }

  }

}

posted on 2007-04-18 16:44  淄衣  阅读(64)  评论(0)    收藏  举报