'C# problems when modify array in DLL function, array pointer as input,wont affect the origin array

I was trying to transport an array pointer 'McuSN' to a DLL function

McuProtocolApi.funMcuReadNumber(bank, page, McuSN, 10);

If I add ref before McuSN,it throws out syntax error.

Here is the declaration of McuSN

private char[] mcusn = new char[11];
public char[] McuSN
{
    get { return mcusn; }
    set
    {
        mcusn = value;
        RaisePropertyChanged();
    }
}

(I wish) this function receive the pointer and modify the value like this

for (int i = 0; i < DataSize; i++)
{
    McuSN[i] = stResponsePackage.data[i];
}

Sadly, it didn't work out.The values in array remain '0',and I'm sure that stResponsePackage.data can perfectly display, Nothing wrong with it. and I make it coding almost the same way in C++.

char McuSN[11];
memset(McuSN, 0, sizeof(McuSN));
ReadMcu_SN(bank, page, McuSN, sizeof(McuSN)-1);

ReadMcu_SN and funMcuReadNumber are the same function in the same DLL.

I don't understand why using C# can't do the same thing like this. It seems like it won't affect the origin array,and if that is the cause,how should I write the right code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source