• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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?
0
djs120
Asked:
djs120
  • 3
  • 2
2 Solutions
 
b1xml2Commented:
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
 
b1xml2Commented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now