[英]C# What is mistyped override ToString() even doing?
In C#, the compiler allows and builds :在 C# 中,编译器允许并构建:
public string Override() { return Name + " : " + StartTime; }
in a object that has a Name string property and StartTime datetime property.在具有 Name 字符串属性和 StartTime 日期时间属性的对象中。 Here is what someone on my team should have coded:这是我团队中的某个人应该编写的代码:
public override string ToString() { return Name + " : " + StartTime; }
What is the original code even doing?原始代码到底在做什么?
The first code example creates a new method called Override()
which returns those properties.第一个代码示例创建了一个名为Override()
的新方法,该方法返回这些属性。 The keyword override
is case sensitive, so the method Override()
is perfectly fine.关键字override
区分大小写,因此Override()
方法非常好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.