Hi...
Difference between convert.tostring and .tostring in c# with example?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 2, 2014, 4:31 AM
As far as ToString("25") is concerned, it depends on what type of instance it's applied to, whether that's type's ToString method has been overloaded to take a string parameter and (if it has) whether "25" is a meaningful value for that parameter.
In the case of the basic numeric types (int, long, double etc), it again returns the string "25" regardless of the value to which it's applied:
In the case of the string or object types, you'll get a compiler error because there is no overload of ToString which takes a string parameter.
Davin MartynPosted Aug 2, 2014, 1:18 AM
VulpesPosted Aug 1, 2014, 2:53 PM
Ramesh MaruthiPosted Aug 1, 2014, 1:15 PM
//Returns a null reference exception for str.
string str;
object i = null;
str = i.ToString();
//Returns an empty string for str and does not throw an exception. If you dont
string str;
object i = null;
str = Convert.ToString(i);