// После поиска в Интернете я использовал следующий код:
public void myMethod(String p_UserName)
{
byte[] logonHours = null;
logonHours = (byte[])de.Properties["logonHours"].Value;
BitArray bitArray = new BitArray(logonHours);
for (int i = 0; i < bitArray.Count; i++)
{
//If bit is zero (that is false), logonHours is Locked
//If bit is one (that is true) then set to zero (false) to LOCK the account
if (bitArray[i])
{
bitArray.Set(i, false);
}
}
byte[] m_Bytes1 = MyExtension.ConvertToByteArray(bitArray);
de.Properties["logonHours"].Value = m_Bytes;
de.CommitChanges();
}
статический класс MyExtension {
public static byte[] ConvertToByteArray(this BitArray bits)
{
int numBytes = bits.Count / 8;
if (bits.Count % 8 != 0) numBytes++;
byte[] bytes = new byte[numBytes];
int byteIndex = 0, bitIndex = 0;
for (int i = 0; i < bits.Count; i++)
{
if (bits[i])
bytes[byteIndex] |= (byte)(1 << (7 - bitIndex));
bitIndex++;
if (bitIndex == 8)
{
bitIndex = 0;
byteIndex++;
}
}
return bytes;
}//end of method
}