Click to See Complete Forum and Search --> : array<int,2>^ to array<int>^?


Venturio
March 27th, 2009, 02:29 PM
Hi, quick question:

Say I have a function "test()" that accepts an array<int>^ as a parameter.
In another function I have a two dimensional array: array<int, 2>^ matrix.

How can I easily pass e.g. the 2nd row of the matrix as a one dimensional array to the test() function?

Thanks.

Alex F
March 28th, 2009, 02:42 AM
I don't think that you can do this unsafe conversion by pure .NET way. But it is possible to do this using native pointers. For example, pin matrix in the memory and pass pointer to its beginning as native int*.
See pin_ptr keyword:
http://msdn.microsoft.com/en-us/library/1dz8byfh(VS.80).aspx

Venturio
March 28th, 2009, 09:26 AM
Thanks, that solved my problem.