Tag: if语句

错误的if语句 – 不能隐式转换types为'布尔'

我有一个转换types的问题。 我正在尝试这样的代码(稍后,详细的代码): string cityType = "City1"; int listingsToSearch = 42; if (cityType = "City1") // <– error on this line { listingsToSearch = 1; } 但是“如果”声明转换城市,但我不断得到: 不能隐式地将types“string”转换为“布尔” 我想要实现的是:我有一个search引擎,它有一个search文本的文本框和两个search位置的单选button(IE City1或City2) 当我收到search文本和单选button时,它们以string的forms出现 string thesearchtext, thecitytype; thesearchtext = HttpContext.Current.Request.QueryString["s"].ToString(); thecitytype = HttpContext.Current.Request.QueryString["bt"].ToString(); 当我收到城市单选button时,它们将采用“城市1”或“城市2”的格式。 我需要做的是将城市单选button转换为int,以便我可以在我的search数据集中使用它们。 我需要将"city"转换为整数1 ,将"city2"为整数2 。 我明白这可能是一个简单的types转换,但我无法弄清楚。 到目前为止的代码, if给我上面的错误: int listingsToSearch; if (thecitytype = "City1") { listingsToSearch […]

是(4> y> 1)在C ++中有效的语句? 你如何评价呢?

这是一个有效的expression? 如果是这样,你可以重写它,使它更有意义吗? 例如,是否与(4 > y && y > 1) ? 你如何评估链式逻辑运算符?

是<布尔expression式> &&语句()与if(<布尔expression式>)语句()相同?

这两个相同吗? 假设你有: var x = true; 然后你有以下其中一个: x && doSomething(); 要么 if(x) doSomething(); 两种语法之间有什么不同? 我绊倒了一点糖吗?

如何在MySQL查询中写入IF ELSE语句

如何在MySQL查询中编写IF ELSE语句? 像这样的东西: mysql_query("…(irrelevant code).. IF(action==2&&state==0){state=1}"); 然后在我的arrays中,我应该能够做到这一点: $row['state'] //this should equal 1, the query should not change anything in the database, //just the variable for returning the information

如果语句匹配多个值

任何更简单的方法来写这个if语句? if (value==1 || value==2) 例如…在SQL中,你可以说where value in (1,2)而不是在where value=1 or value=2 。 我正在寻找的东西,可以与任何基本的types…string,整型等

如何在Angular 4中使用* ngIf?

我正在使用angular4,我想在这个例子中使用*ngIf else : <div *ngIf="isValid"> content here … </div> <div *ngIf="!isValid"> other content here… </div> 我怎么能用ngIf else实现相同的行为呢?

PHP如果声明与多个条件

我有一个variables$var 。 如果$var等于下列值abc , def , hij , klm或nop任何一个,我想回显"true" 。 有没有办法做到这一点与一个单一的声明像&& ??

编译器错误时,如果条件和没有大括号声明一个variables

为什么第一个编译好,第二个编译失败呢? if(proceed) {int i;} // This compiles fine. if(proceed) int i;// This gives an error. (Syntax error on token ")", { expected after this token)

在“if”语句中devise多行条件?

有时候我会把条件分成几行。 最明显的做法是: if (cond1 == 'val1' and cond2 == 'val2' and cond3 == 'val3' and cond4 == 'val4'): do_something 视觉上不太吸引人,因为动作与条件相融合。 但是,使用4个空格的正确Python缩进是自然的方法。 目前我正在使用: if ( cond1 == 'val1' and cond2 == 'val2' and cond3 == 'val3' and cond4 == 'val4'): do_something 但是这不是很漂亮。 🙂 你能推荐一种替代方法吗?

为什么switch语句而不是if-else?

我一直在想这个一段时间了。 我到目前为止不是一个硬核程序员,主要是小型Python脚本,我写了一些分子动力学模拟。 对于真正的问题: switch语句有什么意义? 为什么你不能使用if-else语句 ? 感谢您的回答,如果之前已经询问,请将我指向链接。 编辑 S.Lott指出,这可能是If / Else vs. Switch问题的重复。 如果你想closures然后这样做。 我会留下来进一步讨论。