Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any reasonable use for String.ToString?

I just saw this

string response = GetResponse();
return response.ToString();

Is there any reasonable explanation for using the ToString() method?

like image 684
Jader Dias Avatar asked Dec 04 '22 01:12

Jader Dias


2 Answers

No, there isn't. The only reason why it is available is, because it comes from Object. (And String inherits from Object)

like image 151
Jane Doe Avatar answered Dec 28 '22 07:12

Jane Doe


That does nothing, from ILSpy:

public override string ToString()
{
    return this;
}

But maybe he wants to force a NullReferenceException, although that would not be best-practise.

like image 28
Tim Schmelter Avatar answered Dec 28 '22 07:12

Tim Schmelter