C#中所有的类均继承Object,同样继承了Object中的ToString(),直接调用将会返回类名,往往使用中我们希望它按照我们的想法转换成字符串,这就需要重写ToString()
Object中定义如下:
//
// 摘要:
// Returns a string that represents the current object.
//
// 返回结果:
// A string that represents the current object.
public virtual string? ToString();
重写:
public override string ToString()
{
return "Hello";
}