Jas*_*son 4 c# types casting if-statement
我有转换类型的问题.我正在尝试这样的代码(最小的,详细的代码):
string cityType = "City1";
int listingsToSearch = 42;
if (cityType = "City1") // <-- error on this line
{
    listingsToSearch = 1;
}
但"如果"声明转换城市,但我一直得到:
不能隐式地将类型'string'转换为'bool'
我想要实现的目标:我有一个搜索引擎,其中包含搜索文本的文本框和搜索位置的两个单选按钮(IE City1或City2)
当我收到搜索文本和单选按钮时,它们是一个字符串的形式
string thesearchtext, thecitytype;
thesearchtext = HttpContext.Current.Request.QueryString["s"].ToString();
thecitytype = HttpContext.Current.Request.QueryString["bt"].ToString();
当我收到城市单选按钮时,它们将采用"city1"或"city2"的格式.
我需要做的是将城市radiobuttons转换为int,以便我可以在我的搜索数据集中使用它们.我需要转换"city"为整数1和"city2"整数2.
我知道这可能是一个简单的类型转换,但我无法理解.到目前为止,代码if给出了上面的错误:
int listingsToSearch;
if (thecitytype = "City1")
{
    listingsToSearch = Convert.ToInt32(1);
}
else
{
    listingsToSearch = Convert.ToInt32(2);
}
| 归档时间: | 
 | 
| 查看次数: | 37894 次 | 
| 最近记录: |