C ++ wchar array to C #

I don't have knowledge of C ++, and I need to convert some code to C #. I managed to make a few bits, but I don’t really understand how to convert several lines, so here I ask for help.

This is the C ++ code:

WCHAR wsSerial[MAX_PATH]={'\0'}; WCHAR wsS2[MAX_PATH]={'\0'}; wcscpy_s(wsSerial, MAX_PATH, m_strSerial); wcscpy_s(wsS2,MAX_PATH,wsSerial+8); wsS2[8]=NULL; ULONG ulCode2 = wcstoul(wsS2, NULL,10); 

This is what I have in C #:

  string wsSerial; string wsS2; wsSerial = mSerial; //an external input wsS2 = wsSerial + 8; wsS2= wsSerial.Substring(0, 8); long ulCode2 = long.Parse(wsS2); 

I have two questions:

  • wsSerial is an array in C ++, but I don't need an array for this in C #, right? I mean, all he does is store a large amount, which is later converted to a numerical value, right?
  • What exactly does this do? wcscpy_s (WSS2, MAX_PATH, wsSerial + 8). + 8 throws me away.
+4
source share
3 answers

In C, a string is simply an adjacent region containing a β€œstring” of characters ending in a special character. In other words, an array of char . (Or wchar_t for wide character strings.)

In C # (and C ++), this is not required, since it has its own special string type, which processes the array behind the scenes.


As for the +8 object, it just skips the first eight characters of wsSerial when copying. To understand this, you must read "pointer arithmetic."

+2
source

It looks like you are almost everything, but the first argument in the call

 wsSerial.Substring() 

should be 8, the second should be MAX_PATH minus 8.

+1
source

This is true:

 string wsSerial = mSerial; string wsS2 = wsSerial.Substring(8, 8); long ulCode2 = long.Parse(wsS2); 
+1
source

All Articles