toString() 找不到合适的方法来覆盖
我在这里敲头..
用 C# 给出...
public class ClassA
{
public override string toString()
{
return "use this toString()!";
}
}
当我尝试构建它时,它告诉我:“ClassA.toString():找不到合适的方法来覆盖。”
如果不是这个,如何覆盖 C# 中的默认 toString?
I'm banging my head here..
Given in C#...
public class ClassA
{
public override string toString()
{
return "use this toString()!";
}
}
When I try to build this it tells me: "ClassA.toString(): no suitable method found to override."
How do you override the default toString in C# if not this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的方法是
ToString
The correct method is
ToString
您需要的是 ToString(T 大写)。与 Java 等其他语言相反,C# 的方法名称通常以大写字母开头。与 Java 等其他语言一样,它区分大小写!
您是否有 Java 背景? :-)
It's ToString (with a capital T) that you're after. Contrary to other languages such as Java, C# generally has method names starting with capitals. And like other languages such as Java, it is case sensitive!
Are you coming from a Java background by any chance? :-)