Yesterday i was reading the topic of Collection in c# language and i faced a problem that.
In some Collections like HashTable ,ArrayList ,Dictionary we are not necessary to define the size of Collection like:
ArrayList list = new ArrayList(6); //No error
Hashtable obj = new Hashtable(6); //No error
ArrayList list = new ArrayList(); //No error
Hashtable obj = new Hashtable(); //No error
but in BitArray we can not declare a BitArray without initialize it's size
BitArray obl = new BitArray(6); //No error
BitArray obl = new BitArray(); // It will show an error
why????????
Loading

Manish Kumar ChoudharyPosted Feb 27, 2015, 11:55 PM
// Summary:
// Manages a compact array of bit values, which are represented as Booleans,
// where true indicates that the bit is on (1) and false indicates the bit is
// off (0).
[Serializable]
[ComVisible(true)]
public sealed class BitArray : ICollection, IEnumerable, ICloneable
{
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// contains bit values copied from the specified System.Collections.BitArray.
//
// Parameters:
// bits:
// The System.Collections.BitArray to copy.
//
// Exceptions:
// System.ArgumentNullException:
// bits is null.
public BitArray(BitArray bits);
//
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// contains bit values copied from the specified array of Booleans.
//
// Parameters:
// values:
// An array of Booleans to copy.
//
// Exceptions:
// System.ArgumentNullException:
// values is null.
public BitArray(bool[] values);
//
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// contains bit values copied from the specified array of bytes.
//
// Parameters:
// bytes:
// An array of bytes containing the values to copy, where each byte represents
// eight consecutive bits.
//
// Exceptions:
// System.ArgumentNullException:
// bytes is null.
//
// System.ArgumentException:
// The length of bytes is greater than System.Int32.MaxValue.
public BitArray(byte[] bytes);
//
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// can hold the specified number of bit values, which are initially set to false.
//
// Parameters:
// length:
// The number of bit values in the new System.Collections.BitArray.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// length is less than zero.
public BitArray(int length);
//
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// contains bit values copied from the specified array of 32-bit integers.
//
// Parameters:
// values:
// An array of integers containing the values to copy, where each integer represents
// 32 consecutive bits.
//
// Exceptions:
// System.ArgumentNullException:
// values is null.
//
// System.ArgumentException:
// The length of values is greater than System.Int32.MaxValue
public BitArray(int[] values);
//
// Summary:
// Initializes a new instance of the System.Collections.BitArray class that
// can hold the specified number of bit values, which are initially set to the
// specified value.
//
// Parameters:
// length:
// The number of bit values in the new System.Collections.BitArray.
//
// defaultValue:
// The Boolean value to assign to each bit.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// length is less than zero.
public BitArray(int length, bool defaultValue);
}
Above is the definition of BitArray you can find it by right clicking on BitArray and selecting go to definition.
You can absorb it clearly there is no default constructor defends here that will not accept any parameter so you are getting error.
Pankaj Kumar ChoudharyPosted Feb 28, 2015, 12:05 AM