Re: in a bool 2d array, does Initialize set everything to false?
Yes, although I prefer not to depend upon that behaviour. A quick trip
through the array to initialize each element to false seems a small
price to pay to make my code easier for others (who may not be as
familiar with the finer points of C#) to read.
Re: in a bool 2d array, does Initialize set everything to false?
Hi,
bool is a valued type, therefore it will always has a value, if you do not
assign something it will hold a "default" value. For bool is false , so when
you create a new array it will be initialized to false, you have to do
nothing else.
Now for completeness , let say that you want to initialize it to true , in
this case you will have to iterate in the arrays , there is no other way
(AFAIK) of doing it . Of course without using unsafe code.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Benny Raymond" <benny@pocketro cks.com> wrote in message
news:%2375BepNB GHA.3064@TK2MSF TNGP10.phx.gbl. ..[color=blue]
> Basically what the subject says...
> "in a bool 2d array, does Initialize set everything to false?"[/color]
Re: in a bool 2d array, does Initialize set everything to false?
Benny,
There two types of arrays 2d arrays - multidimensiona l arrays and jagged
arrays jagged. The former are declared as
bool[,] array;
and the latter
bool[][] jaggedArray;
The multidimensiona l array will be initialized with *false*; the jagged
array creation involves more code but at the end of the day will be
initialized with *false* too.
--
Stoitcho Goutsev (100) [C# MVP]
"Benny Raymond" <benny@pocketro cks.com> wrote in message
news:%2375BepNB GHA.3064@TK2MSF TNGP10.phx.gbl. ..[color=blue]
> Basically what the subject says...
> "in a bool 2d array, does Initialize set everything to false?"[/color]
Re: in a bool 2d array, does Initialize set everything to false?
Bruce Wood <brucewood@cana da.com> wrote:[color=blue]
> Yes, although I prefer not to depend upon that behaviour. A quick trip
> through the array to initialize each element to false seems a small
> price to pay to make my code easier for others (who may not be as
> familiar with the finer points of C#) to read.[/color]
Personally I'd prefer to rely on the specified behaviour - if I saw a
loop initialising an array, I'd take a few looks at it to check it was
*actually* a redundant bit of code...
While it's reasonable to try to avoid making readers have to know the
finer points of C#, I don't think array initialization is a
particularly advanced topic.
Comment