ToString vs. ToString() in VB.NET

ToString vs. ToString() in VB.NET

Nothing. VB.NET allows you exclude the parentheses on any method that doesnt take in an argument.

The existing answer is wholly correct but does not cover when ToString is used as a Method. This is essentially incorrect coding but it is possible

Dim sbrBuilder as New StringBuilder

...

sbrBuilder.ToString()
return sbrBuilder.ToString

The first ToString (which does nothing) does not produce an error but the brackets are forced on by the IDE. The second ToString does not require brackets (optional – as explained already in the Answer) as it is used to collect the value of ToString.

Hopefully this will help anyone who is wondering why the IDE keeps adding brackets on ToString – then you will realise that you forgot to assign it to anything like I did

ToString vs. ToString() in VB.NET

Leave a Reply

Your email address will not be published. Required fields are marked *