This is my first post here. I am trying to learn C#, and have no development experience. I found the code below and can not follow what is going on in the sections I have labeled.
I got the code from here.
BitArray implementation of Indexers:
class BitArray
{
int[] bits;
int length;
public BitArray(int length) {
if (length < 0) throw new ArgumentException();
bits = new int[((length - 1) >> 5) + 1];
this.length = length;
}
public int Length {
get { return length; }
}
public bool this[int index] {
get {
if (index < 0 || index >= length) {
throw new IndexOutOfRangeException();
}//What is happening in the line below?
return (bits[index >> 5] & 1 << index) != 0;
}
set {
if (index < 0 || index >= length) {
throw new IndexOutOfRangeException();
}// Also in the if statement below I do not see what is going on
if (value) {
bits[index >> 5] |= 1 << index;
}// Same here in the else block, what is happening?
else {
bits[index >> 5] &= ~(1 << index);
}
}
}
}