我知道
例如,考虑以下VB.NET代码。
此外,对于布尔值,在C#中使用的符号“^”是否等同于Visual Basic中的“Xor”?
AndAlso
相当于&&
,OrElse
相当于||
。但是,在C#中实现与Visual Basic的And
和Or
等效的最简洁方法是什么呢?例如,考虑以下VB.NET代码。
ValidateForControl
方法执行一些验证并返回指定控件状态是否有效。如果所有控件都有效,则整个输入表单有效。但是,即使一个控件无效,每个控件也必须单独进行验证(这需要运算符不短路)。对于这种情况,Visual Basic的And
运算符非常完美,但是据我所知,在C#中没有等效的运算符(&&
会短路)。Return _
Me.ValidateForControl(Me.firstNameTextBox) And
Me.ValidateForControl(Me.middleNameTextBox) And
Me.ValidateForControl(Me.lastNameTextBox) And
Me.ValidateForControl(Me.streetAddressTextBox) And
Me.ValidateForControl(Me.cityTextBox) And
Me.ValidateForControl(Me.stateComboBox) And
Me.ValidateForControl(Me.zipCodeMaskedTextBox) And
Me.ValidateForControl(Me.phoneMaskedTextBox) And
Me.ValidateForControl(Me.emailAddressTextBox) And
Me.ValidateForControl(Me.checkInDateTimePicker) And
Me.ValidateForControl(Me.checkOutDateTimePicker) And
Me.ValidateForControl(Me.rentalUnitsGroupBox)
此外,对于布尔值,在C#中使用的符号“^”是否等同于Visual Basic中的“Xor”?
AndAlso
,&&
只有在操作数之一为False时才会短路。你的意思是“即使一个控件是无效的,每个控件都必须进行验证”吗? - MarkJ