C #: Does String.Format build ToString input?

Does String.Format ToString execute?

For example, if I have an object of a "complex" class, can I do:

 <i>String.Format("String rep. {0}",complexObj);</i>
+4
source share
2 answers

In the documentation:

How arguments are formatted:

Format elements are processed sequentially from the beginning of the line. Each format element has an index that corresponds to an object in the method argument list. The format method extracts the argument and displays its string representation as follows:

  • If an argument null, the method inserts String.Emptyinto the result line.
  • Format(IFormatProvider, String, Object[]), ICustomFormatter, ICustomFormatter.Format(String, Object, IFormatProvider) . formatString, . ICustomFormatter , ; null, .
  • IFormattable, IFormattable.ToString .
  • ToString, , Object, .

, , - - ToString.

+7

System.Object, ToString(), , . , .

public override string ToString()
{
    return "<Insert your output here>"
}
0

Source: https://habr.com/ru/post/1535579/


All Articles