如果声明具有多个条件 [英] If statement with multiple condition

查看:81
本文介绍了如果声明具有多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#在单个if中不允许多个条件?或者我犯了错误

我的语法?当我把and和和时,它一直给我语法错误。或或或在

if statemnt用于多个条件检查。


if((radioAllItems.Checked = TRUE)和

(这个。 lstSelections.SelectedItems.Count< lstSelections.Items.Count));


谢谢,

Alpha

C# doesn''t allow multiple condition in a single if ? Or did I make a mistake
with my syntax? It keep giving me syntax error when I put "and" or "or" in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha

推荐答案

在C#中,你使用&& for和,和||为或。另外!=不等于。


Marcie


星期一,2005年4月4日12:01:02 -0700,Alpha ;

< Al *** @ discussion.microsoft.com>写道:
In C#, you use && for and, and || for or. Also != is not equal to.

Marcie

On Mon, 4 Apr 2005 12:01:02 -0700, "Alpha"
<Al***@discussions.microsoft.com> wrote:
C#在单个if中不允许多个条件?或者我的语法错误了吗?当我把and和和时,它一直给我语法错误。或或或
if statemnt用于多个条件检查。

if((radioAllItems.Checked = TRUE)和
(this.lstSelections.SelectedItems.Count< lstSelections.Items.Count ));

谢谢,
Alpha
C# doesn''t allow multiple condition in a single if ? Or did I make a mistake
with my syntax? It keep giving me syntax error when I put "and" or "or" in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha






Alpha,

C#对逻辑表达式使用不同的语法。对于你想要使用&&,或者你想要使用||,就像这样:


if((radioAllItems.Checked) = TRUE)&&

(this.lstSelections.SelectedItems.Count< lstSelections.Items.Count))


希望这会有所帮助。 />
-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Alpha" <铝*** @ discussions.microsoft.com>在消息中写道

新闻:0D ********************************** @ microsof t.com ...
Alpha,

C# uses a different syntax for logical expressions. For and you want to
use &&, for or, you want to use ||, like so:

if ((radioAllItems.Checked = TRUE) &&
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count))

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C#在单个if中不允许多个条件?或者我用我的语法犯了一个
错误?当我把and和和时,它一直给我语法错误。用于多条件检查的if statemnt中的或或

if((radioAllItems.Checked = TRUE)和
(this.lstSelections.SelectedItems) .Count< lstSelections.Items.Count));

谢谢,
Alpha
C# doesn''t allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha



它的语法:


AND =&&

OR = ||


等式:==(双等于)


if((radioAllItems.Checked == TRUE)&&

(this.lstSelections.SelectedItems.Count< lstSelections.Items.Count ))

{

//做点什么

}


(也没有分号)在if语句结束时)


Alpha <铝*** @ discussions.microsoft.com>在消息中写道

新闻:0D ********************************** @ microsof t.com ...
Its in the syntax:

AND = &&
OR = ||

equality: == (double equal)

if ((radioAllItems.Checked == TRUE) &&
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count))
{
// do something
}

(Also no semi-colon at the end of the if statement)

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C#在单个if中不允许多个条件?或者我用我的语法犯了一个
错误?当我把and和和时,它一直给我语法错误。用于多条件检查的if statemnt中的或或

if((radioAllItems.Checked = TRUE)和
(this.lstSelections.SelectedItems) .Count< lstSelections.Items.Count));

谢谢,
Alpha
C# doesn''t allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha



这篇关于如果声明具有多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆