System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Object
System.Collections.ICollection
System.Collections.IEnumerable
System.ICloneable
[System.Runtime.CompilerServices.Nullable(0)]
[<System.Runtime.CompilerServices.Nullable(0)>]
[System.Serializable]
[<System.Serializable>]
[System.Runtime.InteropServices.ComVisible(true)]
[<System.Runtime.InteropServices.ComVisible(true)>]
Manages a compact array of bit values, which are represented as Booleans, where indicates that the bit is on (1) and indicates the bit is off (0).
class is a collection class in which the capacity is always the same as the count. Elements are added to a by increasing the property; elements are deleted by decreasing the property. The size of a is controlled by the client; indexing past the end of the throws an . The class provides methods that are not found in other collections, including those that allow multiple elements to be modified at once using a filter, such as , , , , and .
The class is a structure that provides the same functionality as , but with faster performance. is faster because it is a value type and therefore allocated on the stack, whereas is a reference type and, therefore, allocated on the heap.
can store exactly 32 bits, whereas can store a variable number of bits. stores both bit flags and small integers, thereby making it ideal for data that is not exposed to the user. However, if the number of required bit flags is unknown, is variable, or is greater than 32, use instead.
is in the namespace; is in the namespace.
Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.
## Examples
The following code example shows how to create and initialize a and how to print out its values.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Overview/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Overview/source.vb" id="Snippet1":::
]]>
Public static ( in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
This implementation does not provide a synchronized (thread safe) wrapper for a .
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
Initializes a new instance of the class whose capacity and initial values can be specified.
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
An array of Booleans to copy.
Initializes a new instance of the class that contains bit values copied from the specified array of Booleans.
is .
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
An array of bytes containing the values to copy, where each byte represents eight consecutive bits.
Initializes a new instance of the class that contains bit values copied from the specified array of bytes.
is .
The length of is greater than Int32.MaxValue.
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
The to copy.
Initializes a new instance of the class that contains bit values copied from the specified .
is .
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
The number of bit values in the new .
Initializes a new instance of the class that can hold the specified number of bit values, which are initially set to .
is less than zero.
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
An array of integers containing the values to copy, where each integer represents 32 consecutive bits.
Initializes a new instance of the class that contains bit values copied from the specified array of 32-bit integers.
is .
The length of is greater than Int32.MaxValue
Constructor
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
The number of bit values in the new .
The Boolean value to assign to each bit.
Initializes a new instance of the class that can hold the specified number of bit values, which are initially set to the specified value.
is less than zero.
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections.BitArray
The array with which to perform the bitwise AND operation.
Performs the bitwise AND operation between the elements of the current object and the corresponding elements in the specified array. The current object will be modified to store the result of the bitwise AND operation.
An array containing the result of the bitwise AND operation, which is a reference to the current object.
.
## Examples
The following code example shows how to perform the bitwise AND operation between two objects.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/And/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/And/source.vb" id="Snippet1":::
]]>
is .
and the current do not have the same number of elements.
Method
M:System.ICloneable.Clone
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Object
Creates a shallow copy of the .
A shallow copy of the .
.
]]>
Method
M:System.Collections.ICollection.CopyTo(System.Array,System.Int32)
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Void
The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing.
The zero-based index in at which copying begins.
Copies the entire to a compatible one-dimensional , starting at the specified index of the target array.
.
## Examples
The following code example shows how to copy a into a one-dimensional .
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/CopyTo/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/CopyTo/source.vb" id="Snippet1":::
]]>
is .
is less than zero.
is multidimensional.
-or-
The number of elements in the source is greater than the available space from to the end of the destination .
The type of the source cannot be cast automatically to the type of the destination .
Property
P:System.Collections.ICollection.Count
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Int32
Gets the number of elements contained in the .
The number of elements contained in the .
and return the same value. can be set to a specific value, but is read-only.
Retrieving the value of this property is an `O(1)` operation.
]]>
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Boolean
The zero-based index of the value to get.
Gets the value of the bit at a specific position in the .
The value of the bit at position .
.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Get/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Get/source.vb" id="Snippet1":::
]]>
is less than zero.
-or-
is greater than or equal to the number of elements in the .
Method
M:System.Collections.IEnumerable.GetEnumerator
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections.IEnumerator
Returns an enumerator that iterates through the .
An for the entire .
also brings the enumerator back to this position. At this position, is undefined. Therefore, you must call to advance the enumerator to the first element of the collection before reading the value of .
returns the same object until either or is called. sets to the next element.
If passes the end of the collection, the enumerator is positioned after the last element in the collection and returns `false`. When the enumerator is at this position, subsequent calls to also return `false`. If the last call to returned `false`, is undefined. To set to the first element of the collection again, you can call followed by .
An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined.
The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
This method is an `O(1)` operation.
]]>
Method
System.Collections
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
netstandard
System.Boolean
Determines whether all bits in the are set to .
if every bit in the is set to , or if is empty; otherwise, .
To be added.
Method
System.Collections
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
netstandard
System.Boolean
Determines whether any bit in the is set to .
if is not empty and at least one of its bit is set to ; otherwise, .
To be added.
Property
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Boolean
Gets a value indicating whether the is read-only.
This property is always .
implements the property because it is required by the interface.
A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.
A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes.
This method is an `O(1)` operation.
]]>
Property
P:System.Collections.ICollection.IsSynchronized
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Boolean
Gets a value indicating whether access to the is synchronized (thread safe).
This property is always .
implements the property because it is required by the interface.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
## Examples
The following code example shows how to lock the collection using the during the entire enumeration.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Overview/source2.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Overview/source2.vb" id="Snippet2":::
This method is an `O(1)` operation.
]]>
Property
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Boolean
The zero-based index of the value to get or set.
Gets or sets the value of the bit at a specific position in the .
The value of the bit at position .
property. Visual Basic implements as a default property, which provides the same indexing functionality.
Retrieving the value of this property is an `O(1)` operation; setting the property is also an `O(1)` operation.
]]>
is less than zero.
-or-
is equal to or greater than .
Method
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
netstandard
2.1.0.0
System.Collections.BitArray
The number of shifts to make for each bit.
Shifts all the bit values of the current to the left on bits.
The current .
is updated and returned.
]]>
is less than zero.
Property
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Int32
Gets or sets the number of elements in the .
The number of elements in the .
and return the same value. can be set to a specific value, but is read-only.
If is set to a value that is less than , the is truncated and the elements after the index `value` -1 are deleted.
If is set to a value that is greater than , the new elements are set to `false`.
Retrieving the value of this property is an `O(1)` operation. Setting this property is an `O(n)` operation.
]]>
The property is set to a value that is less than zero.
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections.BitArray
Inverts all the bit values in the current , so that elements set to are changed to , and elements set to are changed to .
The current instance with inverted bit values.
.
## Examples
The following code example shows how to apply NOT to a .
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Not/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Not/source.vb" id="Snippet1":::
]]>
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections.BitArray
The array with which to perform the bitwise OR operation.
Performs the bitwise OR operation between the elements of the current object and the corresponding elements in the specified array. The current object will be modified to store the result of the bitwise OR operation.
An array containing the result of the bitwise OR operation, which is a reference to the current object.
.
## Examples
The following code example shows how to perform the OR operation between two objects.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Or/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Or/source.vb" id="Snippet1":::
]]>
is .
and the current do not have the same number of elements.
Method
System.Collections
11.0.0.0
mscorlib
netstandard
System.Int32
To be added.
To be added.
To be added.
Method
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
netstandard
2.1.0.0
System.Collections.BitArray
The number of shifts to make for each bit.
Shifts all the bit values of the current to the right on bits.
The current .
is updated and returned.
]]>
is less than zero.
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Void
The zero-based index of the bit to set.
The Boolean value to assign to the bit.
Sets the bit at a specific position in the to the specified value.
.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Get/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Get/source.vb" id="Snippet1":::
]]>
is less than zero.
-or-
is greater than or equal to the number of elements in the .
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Void
The Boolean value to assign to all bits.
Sets all bits in the to the specified value.
.
## Examples
The following code example shows how to set and get specific elements in a .
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Get/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Get/source.vb" id="Snippet1":::
]]>
Property
P:System.Collections.ICollection.SyncRoot
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
System.Object
Gets an object that can be used to synchronize access to the .
An object that can be used to synchronize access to the .
using the property. The synchronizing code must perform operations on the of the , not directly on the . This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the object.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
## Examples
The following code example shows how to lock the collection using the during the entire enumeration.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Overview/source2.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Overview/source2.vb" id="Snippet2":::
Retrieving the value of this property is an `O(1)` operation.
]]>
Method
M:System.Collections.ICollection.CopyTo(System.Array,System.Int32)
System.Collections
4.0.0.0
4.0.10.0
mscorlib
netstandard
System.Void
The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing.
The zero-based index in at which copying begins.
Copies the elements of the to an , starting at the specified index.
To be added.
is null.
is less than zero.
is multidimensional.-or- The number of elements in the source is greater than the available space from to the end of the destination .-or-The type of the source cannot be cast automatically to the type of the destination .
Property
P:System.Collections.ICollection.Count
System.Collections
4.0.0.0
4.0.10.0
mscorlib
netstandard
System.Int32
Gets the number of elements in the .
The number of elements in the .
To be added.
Property
P:System.Collections.ICollection.IsSynchronized
System.Collections
4.0.0.0
4.0.10.0
mscorlib
netstandard
System.Boolean
Gets a value that indicates whether access to the is synchronized (thread safe).
true if access to the is synchronized (thread safe); otherwise, false.
instance is cast to an interface.
]]>
Property
P:System.Collections.ICollection.SyncRoot
System.Collections
4.0.0.0
4.0.10.0
mscorlib
netstandard
System.Object
Gets an object that can be used to synchronize access to the .
An object that can be used to synchronize access to the .
instance is cast to an interface.
]]>
Method
System.Collections
4.0.0.0
4.0.10.0
4.1.0.0
4.1.1.0
4.1.2.0
5.0.0.0
6.0.0.0
7.0.0.0
8.0.0.0
9.0.0.0
10.0.0.0
11.0.0.0
mscorlib
1.0.5000.0
2.0.0.0
2.0.5.0
4.0.0.0
netstandard
2.0.0.0
2.1.0.0
System.Collections.BitArray
The array with which to perform the bitwise exclusive OR operation.
Performs the bitwise exclusive OR operation between the elements of the current object against the corresponding elements in the specified array. The current object will be modified to store the result of the bitwise exclusive OR operation.
An array containing the result of the bitwise exclusive OR operation, which is a reference to the current object.
.
## Examples
The following code example shows how to perform the XOR operation between two objects.
:::code language="csharp" source="~/snippets/csharp/System.Collections/BitArray/Xor/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections/BitArray/Xor/source.vb" id="Snippet1":::
]]>
is .
and the current do not have the same number of elements.