Закрепление фиксированного массива строк и получение char* для каждого индексаC#

Место общения программистов C#
Anonymous
Закрепление фиксированного массива строк и получение char* для каждого индекса

Сообщение Anonymous »


I have to pass a pointer of type char* to a structure in C# and I can successfully do it with this code:

string myText = "Hello World"; fixed (char* ptrText = myText) { lvItem.pszText = ptrText; .... } However, I have to do this 20 times, and I would like to avoid pinning/fixing all 20 strings in a loop and instead populate them in an array of strings and just pin that array (seems more efficient), but I cannot get the part of pinning the whole array and then getting the address of each element as a char* pointer.

string[] arrStrings = new string[20]; fixed (string* ptrArray = arrStrings) { lvItem.pszText = &ptrArray[1] // this doesn't work .... } Anyone knows how is this done in unsafe context in C#?


Источник: https://stackoverflow.com/questions/781 ... each-index

Вернуться в «C#»