14
Reply

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

Brajesh Kumar

Brajesh Kumar

7y
4.9k
4
Reply

    can you Explain with a program

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

    Convert.ToString() handles null, while ToString() doesn't. explanation with C# Code.............. Un Safe code ...................................Try' In this code we will get "Object reference not set to an instance of an object." exceptionDim a As Objecta = Nothinga.ToString()Catch ex As NullReferenceExceptionResponse.Write(ex.Message)End Try'............... it is a safe code..............................Dim b As Objectb = NothingConvert.ToString(b)

    Convert.ToString() handles null value but .ToString() does not handle null value. Example:-string str; object i = null; str = i.ToString();------>It Throws errorstring str; object i = null; str = Convert.ToString(i);-->It does not throgh error

    Convert.ToString() handles null value but .ToString() does not handle null value.

    Convert.ToString() handles null .ToString() not handles null

    Convert.ToString() handles null .ToString() not handles null

    Convet.ToString() will handle null values and ToString not

    Convet.ToString() will handle null values and ToString not

    Convet.ToString() will handle null values and ToString not

    Convet.ToString() will handle null values and ToString not

    Convet.ToString() will handle null values and ToString not

    Convet.ToString() will handle null values and ToString not

    Convert executes before statement