4
Reply

What's the basic difference between convert.ToString() and .ToString() in C#.net

kamal agrawal

kamal agrawal

15y
13.1k
0
Reply

    Lets understand the difference via this example

    int i 0;
    MessageBox.Show(i.ToString());
    MessageBox.Show(Convert.ToString(i));

    We can convert the integer “i” using “i.ToString ()” or “Convert.ToString” so what’s the difference. The basic difference between them is “Convert” function handles NULLS while “i.ToString ()”does not it will throw a NULL reference exception error. So as good coding practice using“convert” is always safe.

    http://kalitinterviewquestions.blogspot.com/

    Convert.ToString can handle null value. Object.ToString() will throw an error if the object is null. so its alway best to use Convert.Tostring() when you are converting reference type to string. Value type cannot be null so you can use .ToString() for value types.

    .ToString() method lets you convert any value to a string.

    W
    hile convert.ToString() method uses the Convert class which provides shared methods that you can use to convert value with any data type to any other data type.