帮助转换类型 - 不能类型“string”隐式转换为“布尔” [英] Help converting type - cannot implicitly convert type 'string' to 'bool'
问题描述
我是相当新的C#和asp.net和我有一个问题转换类型;
I am fairly new to c# and asp.net and am having an issue converting type;
我的情况是,我有一个具有搜索文本和两个单选按钮为搜索位置(IE City1或城2)
My situation is that I have a search engine that has a textbox for the search text and two radio buttons for the search location ( IE City1 or City2 )
当我收到搜索文本和单选按钮他们是在一个字符串的形式
IE
When I recieve the search text and radio buttons they are in the form of a string IE
string thesearchtext, thecitytype;
thesearchtext = HttpContext.Current.Request.QueryString["s"].ToString();
thecitytype = HttpContext.Current.Request.QueryString["bt"].ToString();
当我收到城市单选按钮,他们将在city1或城2。
When I recieve the cities radiobutton they will be in the format of "city1" or "city2".
我需要做的是转换城市单选按钮为一个int,这样我可以在我的搜索数据集中使用它们。 IE浏览器,我需要的城市到1和城2转换为2。
What i need to do is convert the city radiobuttons into an int so that I can use them in my search dataset. IE I need to convert "city" to "1" and "city2" to "2".
我理解这可能是一个简单的类型转换,但是我只是无法弄清楚。
我尝试过的如果语句转换的城市,但我不断收到:
I understand this is probably a simple type conversion however I just cannot figure it out. I tried an "if" statement to convert the cities but I keep getting:
cannot implicitly convert type 'string' to 'bool'
我试图code是这样的:
I was trying code like this:
int listingsToSearch;
if (thecitytype = "City1")
{
listingsToSearch = Convert.ToInt32(1);
}
else
{
listingsToSearch = Convert.ToInt32(2);
}
在指导我在正确的方向任何帮助将大大AP preciated
谢谢...
Any help in guiding me in the right direction would be greatly appreciated Thanks...
推荐答案
尝试:C#相等操作==不是=
try: c# equality operator == not =
if (thecitytype == "City1")
这篇关于帮助转换类型 - 不能类型“string”隐式转换为“布尔”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!