C# 中的 Convert.ToUInt16 方法

programmingserver side programmingcsharp更新于 2025/10/7 23:24:00

使用 Convert.ToUInt16 方法将指定值转换为 16 位无符号整数。

这是我们的字符串 −

string str = "1129";

现在让我们将其转换为 16 位无符号整数。

ushort res;
res = Convert.ToUInt16(str);

以下是完整示例 −

示例

using System;
public class Demo {
   public static void Main() {
      string str = "1307";
      ushort res;
      res = Convert.ToUInt16(str);
      Console.WriteLine("将字符串 '{0}' 转换为 {1}", str, res);
   }
}

输出

将字符串 '1307' 转换为 1307

相关文章