Convert char [,] array to char **

Converting a string to char* easy in C #

 string p = "qwerty"; fixed(char* s = p) 

But does anyone know how to convert char[,] to char** in C #?

+5
source share
1 answer

The code below shows how to convert a char[,] array to a pointer. It also demonstrates how characters can be written to an array and retrieved through a pointer. You can also write with a pointer and read using an array. This is all the same, because it refers to the same data.

  char[,] twoD = new char[2, 2]; // Store characters in a two-dimensional array twoD[0, 0] = 'a'; twoD[0, 1] = 'b'; twoD[1, 0] = 'c'; twoD[1, 1] = 'd'; // Convert to pointer fixed (char* ptr = twoD) { // Access characters throught the pointer char ch0 = ptr[0]; // gets the character 'a' char ch1 = ptr[1]; // gets the character 'b' char ch2 = ptr[2]; // gets the character 'c' char ch3 = ptr[3]; // gets the character 'd' } 
+1
source

Source: https://habr.com/ru/post/1237468/


All Articles