Link: http://zhidao.baidu.com/question/76598974.html
What does public override string tostring () mean?
Public class contact {protected string name; protected string homephone; protected string busiphone; protected string mobilephone; public contact (string name, string home, string Busi, string mobile) {name = Name; homephone = home; busiphone = Busi; mobilephone = Mobile;} public override string tostring () {string temp = string. format ("Name: {0}, Home Phone: {1}, office phone: {2}, mobile phone: {3} \ n", name, homephone, busiphone, mobilephone); Return temp ;}
Override the tostring () method of the object class. All classes in C # inherit from objects. The methods provided by the object can be used in any class. If you do not want to use the object method, you can override it. For example: public class A {public override string tostring () {return "hello ";}}
When you use a. tostring (), the result is "hello". If you do not rewrite tostring, the full name of the class, such as samplenamespaces. A, is returned by default.