vb.net - why Tostring doesnot convert int to string -
consider code:
dim integer = 4 dim c integer = 3 console.writeline(a.tostring + c) console.readline() it should return 43 being converted string still return 7
because need convert both operands string, and/or use string concatenation operator &.
as stands, evaluating expression:
"4" + 3 and vb decides convert first operand integer match second operand. vb perform string concatenation + if both operands strings. prefers arithmetic +.
some useful links:
- http://msdn.microsoft.com/en-us/library/te2585xw.aspx
- http://msdn.microsoft.com/en-us/library/9c5t70w2.aspx
- http://msdn.microsoft.com/en-us/library/wfx50zyk.aspx
as can see these links, setting of option strict plays role. have set off frankly setting on prudent.
personally i'd write this
a.tostring & c.tostring the bottom line if know want concatenate strings, clearer use dedicated string concatenation operator &.
Comments
Post a Comment