当前位置:K88软件开发文章中心编程语言.NET.NET02 → 文章内容

VB.Net - 运算符

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:58:54

由 yiyohunter 创建,小路依依 最后一次修改 2016-12-12 运算符是一个符号,通知编译器执行特定的数学或逻辑操作。 VB.Net丰富的内置运算符,并提供以下类型的常用运算符: 算术运算符比较运算符逻辑/位运算符位移位运算符赋值运算符其他运算符本教程将介绍最常用的运算符。 算术运算符下表显示了VB.Net支持的所有算术运算符。 假设变量A保持2,变量B保持7,则: 显示示例 运算符描述例^Raises one operand to the power of anothe将一个操作数提升为另一个的权力B^A will give 49+Adds two operand添加两个操作数sA + B will give 9-Subtracts second operand from the first从第一个操作数中减去第二个操作数A - B will give -5*Multiplies both operands将两个操作数相乘A * B will give 14/Divides one operand by another and returns a floating point result将一个操作数除以另一个操作数,并返回一个浮点结果B / A will give 3.5\Divides one operand by another and returns an integer result将一个操作数除以另一个操作数,并返回一个整数结果B \ A will give 3MODModulus Operator and remainder of after an integer division模数运算符和整数除法后的余数B MOD A will give 1比较运算符下表显示了VB.Net支持的所有比较运算符。 假设变量A保持10,变量B保持20,则: 显示示例 运算符描述例=Checks if the values of two operands are equal or not; if yes, then condition becomes true.检查两个操作数的值是否相等; 如果是,则条件变为真。(A = B)是不正确的。<>Checks if the values of two operands are equal or not; if values are not equal, then condition becomes true.检查两个操作数的值是否相等; 如果值不相等,则条件为真。(AB)为真。>Checks if the value of left operand is greater than the value of right operand; if yes, then condition becomes true.检查左操作数的值是否大于右操作数的值; 如果是,则条件变为真。(A> B)是不正确的。<Checks if the value of left operand is less than the value of right operand; if yes, then condition becomes true.检查左操作数的值是否小于右操作数的值; 如果是,则条件变为真。(A <B)为真。> =Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then condition becomes true.检查左操作数的值是否大于或等于右操作数的值; 如果是,则条件变为真。(A> = B)是不正确的。<=Checks if the value of left operand is less than or equal to the value of right operand; if yes, then condition becomes true.检查左操作数的值是否小于或等于右操作数的值; 如果是,则条件变为真。(A <= B)为真。除了上述情况外,VB.Net提供了三个比较运算符,我们将在以后的章节中使用; 然而,我们在这里给出一个简短的描述。1、Is运算符 - 它比较两个对象引用变量,并确定两个对象引用是否引用相同的对象,而不执行值比较。 如果object1和object2都引用完全相同的对象实例,则result为True; 否则,result为False。2、IsNot运算符 - 它还比较两个对象引用变量,并确定两个对象引用是否引用不同的对象。 如果object1和object2都引用完全相同的对象实例,则result为False; 否则,result为True。3、Like运算符 - 它将字符串与模式进行比较。逻辑/位运算符下表显示了VB.Net支持的所有逻辑运算符。 假设变量A保持布尔值True,变量B保持布尔值False,则: 显示示例 运算符描述例AndIt is the 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和B)为假。OrIt is the 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或B)为真。NotIt is the logical as well as bitwise NOT operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false.它是逻辑以及按位非运算符。 用于反转其操作数的逻辑状态。 如果条件为真,则逻辑非运算符将为假。没有(A和B)为真。XorIt is the 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。 该运算符不会执行短路,它总是评估这两个表达式,并且没有该运算符的短路对应。异或B为真。AndAlsoIt is the logical AND operator. It works only on Boolean data. It performs short-circuiting.它是逻辑 AND 运算符。它仅适用于布尔型数据。它执行短路。(A AndAlso运算B)为假。OrElseIt is the logical OR operator. It works only on Boolean data. It performs short-circuiting.它是逻辑或运算符。 它只适用于布尔数据。 它执行短路。(A OrElse运算B)为真。IsFalseIt determines whether an expression is False.它确定表达式是否为假。 IsTrueIt determines whether an expression is True.它确定表达式是否为真。 位移运算符我们已经讨论了按位运算符。 位移运算符对二进制值执行移位操作。 在进入位移运算符之前,让我们来了解位操作。按位运算符处理位并执行逐位操作。 &,|和^的真

[1] [2] [3]  下一页


VB.Net - 运算符