如果在C#中检查订单 [英] If Checking order in C#
本文介绍了如果在C#中检查订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们,
我想知道我是否可以像这样使用if statement
if (listView1.SelectedItems.Count> 0&& MessageBox.Show( < span class =code-string>删除此联系人?,Application.ProductName,MessageBoxButtons.YesNo)== System.Windows.Forms.DialogResult.Yes)
{
// 这里有些代码......
}
而不是
if (listView1.SelectedItems.Count> 0)
if (MessageBox.Show( 删除此联系人?,Application.ProductName,MessageBoxButtons.YesNo)== System.Windows.Forms.DialogResult.Yes)
{
// 某些代码h ere ...
}
我希望它仅在所选项目数大于0时才能获得消息框确认... 。
现在都工作正常.....但我担心将来会出现什么问题.... :(: - /:'(
请Helppp .... !!!!
解决方案
据我所知,第一个也是完全有效的。它将检查第一个语句,只检查下一个语句,如果第一个语句是真的...
我在MSDN [ ^ ] [/ EDIT]
是两者都是完美的。但考虑到编码标准第一选项更具可读性。
如果
评估条件表达式(并且短路,请参阅&& Operator(C#Reference) [ ^ ])从左到右。所以第一和第二种形式是等价的,你不必担心未来。 : - )
Hi friends,
I want to know if I can use "if statement" like this
if ( listView1.SelectedItems.Count >0 && MessageBox.Show("Remove this Contact?", Application.ProductName, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
//Some Code here...
}
Instead of
if ( listView1.SelectedItems.Count >0)
if(MessageBox.Show("Remove this Contact?", Application.ProductName, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
//Some Code here...
}
I want it to get the Message Box confirmation only if the selected items count is greater than 0....
Both working fine now..... But I am afraid if any problems will occur in future.... :( :-/ :'(
Please Helppp.... !!!!
解决方案
As far as I know, the fist one is completely valid as well. It will check the first statement and only check the next statement if the first one is true...
[EDIT] I found the proof on MSDN[^] [/EDIT]
Yes both are perferctly fine. But considering the coding standards 1st option is more readable.
if
conditional expression is evaluated (and short-circuited, see "&& Operator (C# Reference)"[^] ) left to right. So first and second forms are equivalent and you don't have to worry about future. :-)
这篇关于如果在C#中检查订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文