C#重写tostring方法
1、重写tostring()方法,第一在需要重写tostring()方法的类中添加tostring方法,代码如图所示:
2、调用重写tostring()方法,代码如图所示:
3、所有的代码如下:using System;namespace HelloWorldApplication{ class HelloWorld { static void Main(string[] args) { /* 我的第一个 C# 程序*/ Console.WriteLine("Hello World"); /*调用重写的方法*/ this.tostring(); Console.ReadKey(); } } /*重写tostring()方法*/ public void tostring(){ Console.WriteLine("您好,世界"); }}
4、输出:Hello World您好,世界!
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:86
阅读量:81
阅读量:70
阅读量:51
阅读量:28