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

来源:这里教程网 时间:2026-02-21 16:21:01 作者:

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);
   }
}

相关推荐