Peter H
Peter H

Reputation: 901

Copying a single array to a multidimensional array

I have declared the following two arrays. One is a single array of 4 elements, The other is a multidimensional array of 5 rows and 4 colums (see diagram below).

array<String^> ^single_row = {"E1", "E2", "E3", "E4"};
array<String^,2>^ multi_row=gcnew array<String^,2>(5,4);

Is there built in function I can use to copy the first array let's say the third row of the second array, without manually copying each element?
Note: I've tried array->copy but experienced error C3262: invalid array indexing: 1 dimension(s) specified for 2-dimensional 'cli::array ^'

I've attached a diagrams to assist for visualisation purposes. Array diagrams

Upvotes: 2

Views: 599

Answers (1)

KooKoo
KooKoo

Reputation: 451

I didn't find any function to do this. The only thing that I've found is that you can create the first array as multidimensional too.

array<String^,2> ^single_row = {{"E1", "E2", "E3", "E4"}};
array<String^,2>^ multi_row=gcnew array<String^,2>(5,4);

Then use:

Array::Copy(single_row,0,multi_row,2*4,4);

I hope this helps.

Kindest Regards

KooKoo

Upvotes: 1

Related Questions