×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net 逻辑/位运算符


VB.Net  运算符VB.Net 运算符


下表显示了VB.Net支持的所有逻辑运算符。 假设变量A保持布尔值True,变量B保持布尔值False,则:

运算符 描述 Example
And It is the vbnet-logical as well as bitwise AND operator. If both the operands are true, then condition becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the expressions.
它是逻辑以及按位AND运算符。 如果两个操作数都为真,则条件为真。 此运算符不执行短路,即,它评估两个表达式。
(A And B) is False.
Or It is the vbnet-logical as well as bitwise OR operator. If any of the two operands is true, then condition becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the expressions.
它是逻辑以及按位或运算符。 如果两个操作数中的任何一个为真,则条件为真。 此运算符不执行短路,即,它评估两个表达式。
(A Or B) is True.
Not It is the vbnet-logical as well as bitwise NOT operator. Used to reverse the vbnet-logical state of its operand. If a condition is true, then Logical NOT operator will make false.
它是逻辑以及按位非运算符。 用于反转其操作数的逻辑状态。 如果条件为真,则逻辑非运算符将为假。
Not(A And B) is True.
Xor It is the vbnet-logical as well as bitwise Logical Exclusive OR operator. It returns True if both expressions are True or both expressions are False; otherwise, it returns False. This operator does not perform short-circuiting, it always evaluates both expressions and there is no short-circuiting counterpart of this operator
它是逻辑以及按位逻辑异或运算符。 如果两个表达式都为True或两个表达式都为False,则返回True; 否则,它返回False。 该运算符不会执行短路,它总是评估这两个表达式,并且没有该运算符的短路对应。
A Xor B is True.
AndAlso It is the vbnet-logical AND operator. It works only on Boolean data. It performs short-circuiting.
它是逻辑AND运算符。 它只适用于布尔数据。 它执行短路。
(A AndAlso B) is False.
OrElse It is the vbnet-logical OR operator. It works only on Boolean data. It performs short-circuiting.
它是逻辑或运算符。 它只适用于布尔数据。 它执行短路。
(A OrElse B) is True.
IsFalse It determines whether an expression is False.
它确定表达式是否为False。
 
IsTrue It determines whether an expression is True.
它确定表达式是否为True。

尝试以下示例来了解VB.Net中提供的所有逻辑/按位运算符:

Module vbnet-logicalOp

    Sub Main()
        Dim a As Boolean = True
        Dim b As Boolean = True
        Dim c As Integer = 5
        Dim d As Integer = 20
        'vbnet-logical And, Or and Xor Checking
        If (a And b) Then
            Console.WriteLine("Line 1 - Condition is true")
        End If
        If (a Or b) Then
            Console.WriteLine("Line 2 - Condition is true")
        End If
        If (a Xor b) Then
            Console.WriteLine("Line 3 - Condition is true")
        End If
        'bitwise And, Or and Xor Checking
        If (c And d) Then
            Console.WriteLine("Line 4 - Condition is true")
        End If
        If (c Or d) Then
            Console.WriteLine("Line 5 - Condition is true")
        End If
        If (c Or d) Then
            Console.WriteLine("Line 6 - Condition is true")
        End If
        'Only vbnet-logical operators
        If (a AndAlso b) Then
            Console.WriteLine("Line 7 - Condition is true")
        End If
        If (a OrElse b) Then
            Console.WriteLine("Line 8 - Condition is true")
        End If

        ' lets change the value of  a and b 
        a = False
        b = True
        If (a And b) Then
            Console.WriteLine("Line 9 - Condition is true")
        Else
            Console.WriteLine("Line 9 - Condition is not true")
        End If
        If (Not (a And b)) Then
            Console.WriteLine("Line 10 - Condition is true")
        End If
        Console.ReadLine()
    End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:

Line 1 - Condition is true
Line 2 - Condition is true
Line 3 - Condition is true
Line 4 - Condition is true
Line 5 - Condition is true
Line 6 - Condition is true
Line 7 - Condition is true
Line 8 - Condition is true
Line 9 - Condition is not true
Line 10 - Condition is true


VB.Net  运算符VB.Net 运算符


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)