Simple Question - Passing Arrays to Functions

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

I need to pass an array from C# to a managed C++ function (that will
in turn call unmanaged C code). My knowledge of managed C++ syntax is
limited (obviously). This needs to be a reference parameter so the
function can change the contents of the array and give it back to the
caller.

How should I declare this array parameter in the managed C++ function?
 
By 'managed' do you mean C++/CLI?
If so, then the following example accepts an integer array by ref:
void Foo(array<int> ^%ThisArray)
{
}
But, unless you are changing the array reference, the following will do:
void Foo(array<int> ^ThisArray)
{
}
You do not have to pass by ref if just changing the contents of an array
since the array reference is not changing.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
By 'managed' do you mean C++/CLI?
If so, then the following example accepts an integer array by ref:
void Foo(array<int> ^%ThisArray)
{}

But, unless you are changing the array reference, the following will do:
void Foo(array<int> ^ThisArray)
{}

You do not have to pass by ref if just changing the contents of an array
since the array reference is not changing.
--
David Antonwww.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter






- Show quoted text -

PERFECT - That is exactly what I needed. Thanks very much!
 
Back
Top