Thanks for the System::Char pointer.
Interestingly the uncommented line gives my desired effect. The
commented line gives the same result as previously.
Can anyone enlighten me?
{
unsigned int checksum = 0;
System::Char checksum_string[2];
System::String^ message;
for(int i=0; i<stuffed_message->Length; ++i)
{
checksum += stuffed_message[i];
}
checksum_string[0] = (checksum>>8)&0xff;
checksum_string[1] = checksum&0xff;
//message += checksum_string[0] + checksum_string[1];
message += "" + checksum_string[0] + checksum_string[1];
}
I think I may have answered my own question in looking at these two
lines again. The + in the commented line performs an arthimetic
addition on the 'Char' values which is why I get "156" and not "0156"
for the binary checksum (expressed as hex) 0x009C. And in the
uncommented line the empty string forces the + to be consider as a
string concatenation.
This still leaves me with when does a value get converted to a text
string and when does it remain it's original value?
The following also gives my desired result. Not that I think it sheds
any further light on it for me.
message += checksum_string[0];
message += checksum_string[1];
and
message = message + checksum_string[0] + checksum_string[1];
Instead of thinking the number is 'promoted' to a string think in terms
of method overloading.
There are 3 compiler defined methods:
string operator +( string,x, string y);
string operator +( object,x, string y);
string operator +( string,x, object y);
Effectively, all 3 do a concat( x.ToString(), y.ToString() ), where a
null is considered an emtpy string;