Jane
Jane

Reputation: 27

How to use array parameter in c# using CLI function?

I want to use array in C# using CLI function.

CLI Source

public value struct Test
{
    int         nIndex;
    TArrTest    Arr;    // TArrTest : Array struct
}

void Api::Set_Test(array<Test^>^% _Test2)

C# Source

Test[] Test3 = new Test[5];
test3[0].nIndex = 0;
...
...
Api.Set_Test(ref Test3) // Error message

Error Message: The parameter is not convert ref Test[] to ref system.Value[].

How can I call Set_Test in C#?

Upvotes: 2

Views: 165

Answers (1)

Mark Benningfield
Mark Benningfield

Reputation: 2892

Your C++/CLI declaration:

void Api::Set_Test(array<Test^>^% _Test2)

is incorrect. The array is not an array of Test references, since Test is a value type. It should be

void Api::Set_Test(array<Test>^% _Test2)
                             ^------ remove the reference caret inside the angle brackets

Upvotes: 1

Related Questions