When should I use XmlConvert.ToString to convert a given value versus the ToString method on the given type.
For example :
int inputVal = 1023;
I can convert this inputVal to string representation using either method:
string strVal = inputVal.ToString();
or
string strVal = XmlConvert.ToString(inputVal);
What is the rule for using XmlConvert.ToString versus doing plain Object.ToString.
The
XmlConvert.ToStringmethods are locale independent so the string representation will be consistent across different locales. WithObject.ToStringyou may get a different representation according to the current culture associated with the thread.So using one versus the other is a matter of the scenario,
XmlConvertlends well if you’re exchanging data with another system and want a consistent textual representation for example adoublevalue.You can see the differences in the following example: