目录

Show Example

下表显示了F#语言支持的所有比较运算符。 这些二进制比较运算符可用于整数和浮点类型。 这些运算符返回bool类型的值。

假设变量A保持10,变量B保持20,则 -

操作者 描述
= 检查两个操作数的值是否相等,如果是,则条件变为真。 (A == B)不是真的。
<> 检查两个操作数的值是否相等,如果值不相等则条件变为真。 (A <> B)是真的。
> 检查左操作数的值是否大于右操作数的值,如果是,则条件变为真。 (A> B)不是真的。
< 检查左操作数的值是否小于右操作数的值,如果是,则条件变为真。 (A < B) 为真
>= 检查左操作数的值是否大于或等于右操作数的值,如果是,则条件变为真。 (A> = B)不是真的。
<= 检查左操作数的值是否小于或等于右操作数的值,如果是,则条件变为真。 (A <= B)是真的。

例子 (Example)

let mutable a : int32 = 21
let mutable b : int32 = 10
if (a = b) then
   printfn "Line 1 - a is equal to b"
else
   printfn "Line 1 - a is not equal to b"
if (a < b) then
   printfn "Line 2 - a is less than b"
else
   printfn "Line 2 - a is not less than b"
if (a > b) then
   printfn "Line 3 - a is greater than b"
else
   printfn "Line 3 - a is not greater than b"
(* Lets change value of a and b *)
a <- 5
b <- 20
if (a <= b) then
   printfn "Line 4 - a is either less than or equal to b"
else
   printfn "Line4 - a is a is greater than b"

编译并执行程序时,它会产生以下输出 -

Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
Line 4 - a is either less than or equal to b
↑回到顶部↑
WIKI教程 @2018