3
Reply

difference between convert.tostring and .tostring

stg

stg

17y
14k
0
Reply

    It is true that conver.tostring return zero if the inputed string is null but .to string it that case raise exception.But if you sure that the inputed string is not null,then it is better to use .tostring method instead of convert.tostring

    Hello

    Convert.toString(.........) handles null while i.tostring() does not handles null.

    Thnx

    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.