如何在 C# 中将字符串转换为 int?
csharpprogrammingserver side programming更新于 2025/5/26 3:22:17
假设我们的字符串是 −
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);
}
}

