char* pointer from string in C#

Viewed 86622

Is it possible to get a char* for a string variable in C#?

I need to convert a path string to a char* for using some native win32 function ...

7 Answers

Like some other posts pointed out, fixed (char* p = str) is not really compatible with native format and StringBuilder does not really work either. This is what worked for me:

fixed (byte* p = Encoding.ASCII.GetBytes(str))
{
    native_call((char*)p);
}
Related