Override overrides the tostring () method of the object class.

Source: Internet
Author: User

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.
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.