|
-
July 22nd, 2008, 06:41 AM
#1
Convert.ToByte(MyString) concatination problems, is it converted then converted back?
Hi :-)
I'm having a very strange problem with Convert.ToByte(MyString)
Is it converted to the byte then converted back? as i'm getting concatination when I attempt to add to it again, and multiplycation ect is saying its still a string, even though I have done the convert and done some maths with it b4.
Here is some code to demostrate this weirdness...
This throws out the number 8, which is correct.
Code:
string myString = "10";
Console.WriteLine(Convert.ToByte(myString) - 2);
This just concatenates (as I understand it, C# has overloaded operators so this is correct but that still means there is no conversion happening)
Code:
string myString = "10";
Convert.ToByte(myString);
myString += 2;
Console.WriteLine(myString);
This says its still a string.
Code:
string myString = "10";
Convert.ToByte(myString);
myString -= 2;
As you can tell this is confusing the hell out of me, I want to convert my string to a byte so I can do some maths on it, I can do that, but it doesn't stay converted.... why?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|