"mac" <no**@none.comwrote:
Assume you have a textbox named "displayValue"
What is the difference (if any) between these two approaches:
1.)
float var;
var = 0.42F;
displayValue.Text = var.ToString
ToString() can accept IFormatProvider and a string format, making it
more flexible. If you have a custom value type and it overrides
ToString(), then calling it directly on the instance won't cause boxing.
2.)
float var;
var = 0.42F;
displayValue.Text = Convert.ToString(var);
This will call var.ToString, and may cause boxing if your value type is
not special-cased by Convert (float is, of course).
Is one way generally preferred over the other?
I personally never use the Convert class except for Base64 conversions.
For most "display value" kind of conversions, I typically use
string.Format().
-- Barry
--
http://barrkel.blogspot.com/