开发者

What is a solution to this "unintended reference comparison" error?

        if (submit.C开发者_如何学编程ontent.Equals("Submit"))

I'm trying to test if the content in a button called submit = "submit". However, this code doesn't work.


The type of the Content property is Object, so you will be calling the Object.Equals method rather than the String.Equals method. The string method compares string values, while the object method only compares the references.

You can just apply the method to the string instead to make it a string comparison instead of a reference comparison:

if ("Submit".Equals(submit.Content))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜