开发者

toString() no suitable method found to override

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?


The correct method is ToString


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? :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜