Skip to content

CUSHORT


将数值或字符串表达式转换为无符号整数(Ushort

语法

vb
declare function Cushort ( byval expression as datatype ) as ushort

Type typename

declare operator cast ( ) as ushort

End Type

用法

vb
result = Cushort( numeric expression )
result = Cushort( string expression )
result = Cushort( user defined type )

参数

expression

要转换为 Ushort 值的数值、字符串或指针表达式

datatype

任何数值、字符串或指针数据类型

typename

用户自定义类型

返回值

Ushort 值。

说明

Cushort 函数舍去小数部分并返回 16 位 Ushort 值。该函数不检查溢出,对于小于 0 或大于 65535 的值,结果是未定义的。

函数名可以理解为"转换为无符号短整型"(Convert to Unsigned Short)。

如果参数是字符串表达式,则使用 Valuint 将其转换为数值。

示例

start GeSHi

vb
' Using the CUSHORT function to convert a numeric value

'Create an USHORT variable
Dim numeric_value As UShort

'Convert a numeric value
numeric_value = CUShort(36000.4)

'Print the result, should return 36000
Print numeric_value
Sleep

end GeSHi

方言差异

  • -lang qb 方言中不可用,除非使用别名 __Cushort 引用。

与 QB 的差异

  • FreeBASIC 新增特性

另请参阅

  • Cbyte
  • Cubyte
  • Cshort
  • Cint
  • Cuint
  • Clng
  • Culng
  • Clngint
  • Culngint
  • Csng
  • Cdbl

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系