转换问题:请阅读以下内容 [英] Conversion Issue : Read Below
本文介绍了转换问题:请阅读以下内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写此代码&它显示转换错误.我尝试过,但找不到答案.
I am writing this code & it show conversion error. I try it but doesn''t find answer.
string requestedDomain = HttpContext.Current.Request.Url.ToString().ToLower();
if ((requestedDomain.IndexOf("http://yoursite.com") + 1))
This if condition show error : Can not implicity convert type int to bool
推荐答案
if(var)
是布尔值检查的语法
你应该这样使用
is syntax if bool value check
you should use like this
if(var == value)
if ((requestedDomain.IndexOf("http://yoursite.com") + 1) == someintvalue)
方法string.IndexOf()
返回一个整数.您应该通过将结果与零进行比较来扩展该表达式以使其为布尔值.
The method string.IndexOf()
returns an integer. You should expand the expression to make it a boolean by comparing the result to zero.
我认为错误消息是不言自明的.您正在尝试评估IF块中的int,并且它应该是布尔值.
您的代码应如下所示:
I think the error message is self explanatory. You are try to evaluate a int in a IF Block, and it should be a boolean.
Your code should look something like this:
if ((requestedDomain.IndexOf("http://yoursite.com") + 1) > 1)
{
// > 1 is just an example...
}
这篇关于转换问题:请阅读以下内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文