在 C# 中将字符串转换为整数的方法


假设我们的字符串为 -

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-6 月 -2020

293 次浏览

开始你的 职业

完成课程即可获得认证

开始
广告
© . All rights reserved.