/// /// "Click" class definition. /// summary> public class point: system.iformtable {/// /// Point class horizontal length coordinates. /// summary> private int m_x, m_y;
/// /// Point class configuration (parameter is a horizontal unit value). /// summary> /// param> /// param> public point (int x, int y) {m_x = x ; M_y = y;}
#Region iFormatTable member
/// /// Used to generate a function of a format string. /// summary> /// format string. param> /// area format information object. param> /// return (string format, iformatprovider formatProvider) {String RetString; try {// Judgment format string. Switch (Format.toupper ()) {CASE "G": // Customized general format. RetString = string.format ({0}, {1}) ", m_x, m_y); //" Point "object's string format is:" (decimal number, decimal number) ". Break; Case "S": // Customized standard format. Retstring = string.format (formatProvider, "<{0}, {1}>", m_x, m_y); // "Point" object string format is: "". Break; default: // Customize the default format. Retstring = string.format (formatProvider, "({0: x}, {1: x}", m_x, m_y); // "Point" object string format is: "(hexadecimal number, ten Six reformed numbers). Break;
}}} Catch (System.NullReferenceException) {// Format string is empty, return to the universal format. Retstring = string.format (formatProvider, "({0}, {1})", m_x, m_y);} return rettstring;
#ndregion
}
/// /// TEST summary description. /// summary> public class test {public static void main () {// Defines a point. Point P = New Point (13, 10); // Print the point of the default format. Console.writeline ("{0}", p); // prints the point of the standard format. Console.WriteLine ("{0: S}", P); / * * Output: (13, 10) * <13, 10> * /}}
/ * * Note: If you do not implement iformattable interfaces, you can also print the custom class object with String.Format, but string.format method * just calls the Object.toString method to print the class name. Below is String.Format These methods call TOSTRING processing sequence: * * 1. Return empty string (") if the value of the object to format is NULL. * 2. If the class to format the object belonging to implement the ICUSTOMMATTER interface, call the icustomatter.format method. * 3. If the previous icomformatter.format method is not called, and the class implements the IFORMATTABLE interface, call the * iformattable.toString method. * 4. If the previous step is not formatted, call the TSTRING method of this type (inherited from the Object class). * * However, only the IFORMATTABLE or ICUSTOMMATTER is implemented to identify the format string we define, print out the results you want. * /