Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Convert.ToString() and .ToString() in C#? [duplicate]

Tags:

c#

ado.net

Possible Duplicate:
variable.ToString() vs. Convert.ToString(variable)

What is the difference between Convert.ToString() and .ToString() in C#?

When I try and convert dataRow[i] to a string using ToString() then I receive an error. How do I fix this?

like image 665
SUJEET Avatar asked Sep 03 '11 05:09

SUJEET


People also ask

What is the difference between convert toString () and toString ()?

Both these methods are used to convert a value to a string. The difference is Convert. ToString() method handles null whereas the ToString() doesn't handle null in C#. In C# if you declare a string variable and if you don't assign any value to that variable, then by default that variable takes a null value.

What is the difference between convert toString () and toString () Mcq?

But yes, there is a difference between them and the main difference is that Convert. Tostring() function handles the NULL while the . ToString() method does not and it throws a NULL reference exception. So, it is a good programming practice to use Convert.

What is to toString () method for?

The toString() method can be used to convert a string object into a string.

How do I convert toString?

ToString(Int32, IFormatProvider) Converts the value of the specified 32-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.


1 Answers

Basically both are used to convert a value to a String but there is a basic difference between them:

When we have an NULL object, Convert.ToString(Object); handles the NULL value whereas Object.ToString(); does not handle the NULL value and it throws NULL Reference Exception.

like image 144
Radhika Avatar answered Sep 28 '22 14:09

Radhika