如何将字符串转换为 C# 中的 int?


假设我们的字符串是 −

string str ="9999";

现在,使用 Int32.Parse() 将字符串转换为整数 −

int n = Int32.Parse(str);

现在显示整数值,如以下代码所示 −

示例

using System;
class Demo {
   static void Main() {
      string str ="9999";
      int n = Int32.Parse(str);
      Console.WriteLine(n);
   }
}

更新日期:22-Jun-2020

295 次浏览

开启你的 职业生涯

完成课程即可获得资格认证

开始学习
广告
© . All rights reserved.