Pedro wrote:
I have this class:
public class Test
{
protected System.Collections.Specialized.BitVector32 _bv32;
public System.Collections.Specialized.BitVector32 BV32 {
get { return _bv32; }
set { _bv32 = value; }
}
public Test()
{
_bv32 = new System.Collections.Specialized.BitVector32(33);
_bv32[1] = false;
}
}
Why if i do:
Test test = new Test();
int a = test.BV32.Data;
test.BV32[1] = false; // DOESN'T COMPILE!!!
it generates a compiler error in the last line???
As you can see in the Test constructor i can do:
_bv32[1] = false
FYI, I'm using VS.NET 2002.
I'm going crazy, please help me.
Other posts have explained why you get the error. But, what you can do
to avoid the problem is create you own indexer property:
public bool this [int index] {
get {
if ((index < 0) || (index > 31)) {
throw new IndexOutOfRangeException();
}
int bit = (1 << index);
return _bv32[bit];
}
set {
if ((index < 0) || (index > 31)) {
throw new IndexOutOfRangeException();
}
int bit = (1 << index);
_bv32[bit] = value;
}
}
Note that this indexer treats the BitVector32 as an array of bool, which
may not be what you want, but I think it's what you were going for.
The int indexer in the BitVector32 class uses the index as a bitmask,
and you're supposed to use the CreateMask() methods to set up indexers
that access individual bits - which I found extremely unintuitive. I
wonder why it was designed that way.
--
mikeb