Re: foreach doesn't work with array of bools?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mattias Sjögren (mattias.dont.want.spam_at_mvps.org)
Date: 08/04/04


Date: Wed, 04 Aug 2004 17:40:53 +0200

Joe,

>What is going on?

Exactly what the compiler says. The variable in a foreach statement is
read only.

>Also, the array of bools seems to have intialized to false anyway. Can I
>count on that?

Yes you can. When you create a new array, all elements have their
default initial value. For bool, that's false.

>Should I even worry about initializing them?

I wouldn't waste CPU cycles on it.

Mattias

-- 
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Relevant Pages

  • Re: fast return value
    ... >be much faster then adding each string to the array one at a time.) ... that's what the compiler ends up doing anyway. ... Please reply only to the newsgroup. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Idea for ECMA/C# Standard - compile time hash for performance
    ... I agree with you the chance of a compiler change is slim, ... and then delegating to the standard hash for fields accessed less frequently. ... or the array lookup which would require the ... > 64-bit architecture) for each enum value that doesn't map to anything. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Q: Checking the size of a non-allocated array?
    ... an actual argument is already invalid ... First note that you don't have an unallocated array in the subroutine. ... it is comparable to disassociated or undefined pointers. ... Obviously the compiler has ...
    (comp.lang.fortran)
  • Re: Windows array allocation problem
    ... array reference has to have a 64-bit index or array subscript triplet? ... to fit in one. ... That assumes, of course, that your compiler ... limits on just about anything. ...
    (comp.lang.fortran)
  • Re: Error handling library
    ... which lets the compiler catch out-of-range usage. ... and assuming that a higher int means "more dangerous error" ... with a comment warning that one is used as an index into the array ... languages while running (an array of languages, ...
    (comp.lang.c)