Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conventions for ToString

What are the conventions for ToString() overrides? The class in question has both a Name property, but also an Id.

like image 213
Philippe Avatar asked Nov 26 '12 12:11

Philippe


People also ask

What is toString () method in Java?

Java - toString() Method The method is used to get a String object representing the value of the Number Object. If the method takes a primitive data type as an argument, then the String object representing the primitive data type value is returned.

What is toString () and why we need it?

The toString method is used to return a string representation of an object. If any object is printed, the toString() method is internally invoked by the java compiler. Else, the user implemented or overridden toString() method is called.

Which of the following is toString () method defined?

The toString() method of java.lang.Package class is used to get the String representation of this package instance. The method returns the String representation as a String value. Syntax: public String toString()

What is toString in C?

The tostring() function is used to convert an integer to string & vice-versa.


1 Answers

Do what you need to do. There's no convention per-se, as there is when overriding something like .Equals() and .GetHashCode().

If you want to influence what appears in the debugger when you break during execution, don't use ToString() - use DebuggerDisplayAttribute.

like image 105
tomfanning Avatar answered Sep 20 '22 05:09

tomfanning