J
Joe Rattz
Hmmm, I wrote the following code. I want an array of bools and I want to
intialize them to false.
bool[] bits = new bool[10];
foreach(bool bit in bits)
{
bit = false;
}
The compiler complains on the "bit = false;" stating that bit is read-only.
If I iterate using an index though, it compiles just fine:
for(int i = 0; i < bits.Length; i++)
{
bits = false;
}
That compiles just fine. What is going on?
Also, the array of bools seems to have intialized to false anyway. Can I
count on that? Should I even worry about initializing them?
Thanks.
intialize them to false.
bool[] bits = new bool[10];
foreach(bool bit in bits)
{
bit = false;
}
The compiler complains on the "bit = false;" stating that bit is read-only.
If I iterate using an index though, it compiles just fine:
for(int i = 0; i < bits.Length; i++)
{
bits = false;
}
That compiles just fine. What is going on?
Also, the array of bools seems to have intialized to false anyway. Can I
count on that? Should I even worry about initializing them?
Thanks.