Problem declaring multiple arrays of same type in one declaration

For some reason this works:

protected bool[,] localYields      = new bool[2,1];
protected bool[,] convPricesExist      = new bool[2,1];
protected bool[,] orgPricesExist      = new bool[2,1];

but this doesn't:
protected bool[,] localYields, convPricesExist, orgPricesExist = new bool[2,1];

I thought you could declare multiple arrays at once as long as they are the same type?
LVL 1
djs120Asked:
Who is Participating?
 
b1xml2Connect With a Mentor Commented:
only orgPricesExist is assigned to new bool[2,1] whereas the localYields and convPricesExist are of the type bool[,] but have yet to be assigned.

0
 
b1xml2Connect With a Mentor Commented:
just like
string value, values, text = string.Empty;

all three variables are string but only the last one has been instantiated, assigned a value, the first 2 are still null
0
 
djs120Author Commented:
Is there a way to instantiate all three to "new bool[2,1]"?
0
 
b1xml2Commented:
nope.
you;ll have to stick with the original code
protected bool[,] localYields     = new bool[2,1];
protected bool[,] convPricesExist     = new bool[2,1];
protected bool[,] orgPricesExist     = new bool[2,1];


0
 
djs120Author Commented:
OK, that confirms my suspicion and I learned a little bit.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.