且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

***的方式来存储/检索位C#

更新时间:2022-12-31 08:32:17

为什么不使用专门设计的类的 BitArray

Why not use a specially designed class BitArray?

http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k(System.Collections.BitArray);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-csharp)&rd=true

例如

  BitArray array = new BitArray(150); // <- up to 150 bits

  ...
  array[140] = true;  // <- set 140th bit 
  array[130] = false; // <- reset 130th bit 
  ...
  if (array[120]) {   // <- if 120th bit is set
    ...