开发者

toString() no suitable method found to override

开发者 https://www.devze.com 2023-02-03 18:40 出处:网络
I\'m banging my head here.. Given in C#... public class ClassA { public override string toString() { return开发者_运维知识库 \"use this 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?


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

精彩评论

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

关注公众号