Udostępnij za pośrednictwem


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

  • Anonymous
    August 11, 2008
    PingBack from http://www.easycoded.com/conversion-between-systemstring-and-char

  • Anonymous
    August 12, 2008
    That is a managed char*, so it's unicode. What would that be useful for? Hardly a surprise that this would work ...

  • Anonymous
    October 13, 2008
    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!