Conversion between System.String and char *

We can convert a char * to System.String with System.String’s constructor

string str = new string((char*)p);

And for the reverse:

fixed(char *p = str){}

Why do we care about conversion between System.String and char *?

From this article, this is the fastest way to marshal strings between managed and native boundary.

Comments (3)
  1. Brian says:

    That is a managed char*, so it’s unicode. What would that be useful for?

    Hardly a surprise that this would work …

  2. Artem Razin says:

    Sorry for the bothering you. It seems that you’re guru of SxS, and I have one interesting question regarding SxS. May I write you a question somehow?… How can I contact you?

    Thank you in advance!

Comments are closed.

Skip to main content