When I wrote C # code yesterday, I encountered a small problem about formatting strings. I retrieve the complete date (including time) from the database, but I only want to display the time on the interface, not the date. So I want to use the ToString ("HH: mm") method. The specific statement is as follows: Table. rows [0] ["Time"]. toString ("HH: mm") but the problem arises. The Compiler prompts that the "ToString" method does not use any overload parameter. But I have seen such a usage. How can I change it? So I checked the materials for a while and finally found the answer to the question. In fact, the problem lies in my lack of solid knowledge about C #. in C #, all classes inherited from objects have tostring () methods. Without special declarations, classes in C # are inherited from objects by default, so the tostring () method is available. However, not all classes have the same tostring () method, because there are overwrites and reloads, which leads to different functions of the toString method. I mistakenly thought that the toString methods of all classes are identical. The basic knowledge is not solid enough to be further consolidated! The following is an example of class rewriting and reload ToString methods on MSDN. You can refer to this example to help us understand the nature of ToString methods. [Csharp] public class Temperature: IFormattable {private decimal temp; public Temperature (decimal temperature) {if (temperature <-273.15 m) throw new ArgumentOutOfRangeException (String. format ("{0} is less than absolute zero. ", temperature); this. temp = temperature;} public decimal Celsius {get {return temp;} public decimal Fahrenheit {get {return temp * 9/5 + 32 ;}} public decimal Kelvin {get {return temp + 273.15 m;} public override string ToString () {return this. toString ("G", CultureInfo. currentCulture);} public string ToString (string format) {return this. toString (format, CultureInfo. currentCulture);} public string ToString (string format, IFormatProvider provider) {if (String. isNullOrEmpty (format) format = "G"; if (provider = null) provider = CultureInfo. currentCulture; switch (format. toUpperInvariant () {case "G": case "C": return temp. toString ("F2", provider) + "°C"; case "F": return Fahrenheit. toString ("F2", provider) + "°F"; case "K": return Kelvin. toString ("F2", provider) + "° K"; default: www.2cto.com throw new FormatException (String. format ("The {0} format string is not supported. ", format ));}}}