开发者

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

开发者 https://www.devze.com 2023-03-30 04:02 出处:网络
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
        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

精彩评论

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