Converting string to char*
is easy in c#
string p = "qwerty";
fixed(char* s = p)
But does anyone know how to convert char[,]
into char**
in c#?
The code below shows how to convert a char[,]
array to a pointer. It also demonstrates how chars can be written into the array and retrieved through the pointer. You could also write using the pointer and read using the array. It's all the same, as it references 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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With