I know that we can initialise an array in one of two ways:
- Loop (No Memory reflection issues)
Enumerable.Repeat(Probably causes memory issues? Link: Enumerable.Repeat has some memory issues?)
I have two questions:
-
Can we initialise an array using
Array.ForEachin this manner?double[][] myarr = new double[13][]; Array.ForEach(myarr, *enter_code_here*);I tried replacing
enter_code_herewith:s => s = new double[2];but it does not initialise
myarr. -
What are the other array initialisation methods without any memory issues?
You can use
Enumerable.Repeatjust fine to initialize any array. The only thing you need to be careful of is that if the array element is of a reference type there are two ways to go about it: