473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

in a bool 2d array, does Initialize set everything to false?

Basically what the subject says...
"in a bool 2d array, does Initialize set everything to false?"
Dec 19 '05 #1
5 12478

Benny Raymond wrote:
Basically what the subject says...
"in a bool 2d array, does Initialize set everything to false?"


Creating a 2d array:

bool[,] myBools = new bool[5,5];

will initialize the values (all 25 of them) to false.

is that what you are asking?

matt

Dec 19 '05 #2
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.

Dec 19 '05 #3
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" <be***@pocketrocks.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Basically what the subject says...
"in a bool 2d array, does Initialize set everything to false?"

Dec 19 '05 #4
Benny,

There two types of arrays 2d arrays - multidimensional arrays and jagged
arrays jagged. The former are declared as
bool[,] array;
and the latter
bool[][] jaggedArray;

The multidimensional 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" <be***@pocketrocks.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Basically what the subject says...
"in a bool 2d array, does Initialize set everything to false?"

Dec 19 '05 #5
Bruce Wood <br*******@canada.com> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michelle | last post by:
Hi all, I am trying to store data in a $_SESSION variable (an array), but it reverts to empty every time my page is refreshed (due to a submit button click). I read the answer to the post...
2
by: Harry Haller | last post by:
Why does the following work: // (1) Set new cookies setcookie ("font_type", $type_sel, time()+3600); setcookie ("font_size", $size_sel, time()+3600); // (1) Get most recent cookie $font_type =...
1
by: kelkel | last post by:
I've created 5 threads to work in my program and I've also created a thread to monitor all 5 threads had still alive or not. Below is part of the monitor thread. bool threadState; threadState =...
4
by: gpg | last post by:
I am using a legacy DLL and need to marshal some structures for use in the DLL. For the most part, I have figured out my needs except for one small item. I have a structure that contain, among...
32
by: Simon L | last post by:
BOOL bMyarray; memset(bMyArray , 0xFF, sizeof(BOOL) * 1000); clean & quick until someone else's code found I was returning -1 to mean true Because my BOOL is 4 bytes long, TRUE in memory...
21
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I really didn't know how to describe that in the title, so I hope I can explain it better here. Basically I want to generate a random 8x8 array of boolean values (I'll actually be using either an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.