gpt4 book ai didi

c# - 如何在 C# 中将某个 string[index] 转换为 int?

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:00 26 4
gpt4 key购买 nike

我有这个代码:

string number = "124235245423523423", number2 = "3423525232332325423";
for(i=number.length-1;i>=0;i--){
int save = Convert.ToInt32(number[i]) + Convert.ToInt32(number2[i]);
}

那不是完整的代码,但我的问题是为什么我不能将字符串的某个索引处的某些值作为整数转换和访问?对此没有直接的方法吗?我尝试了一些事情,但没有成功。

最佳答案

您正在寻找 int.Parse

int save = int.Parse(number[3].ToString());

char 转换为 Int32 会返回当前编码中该字符的值。

有关详细信息,请参阅 the MSDN documentation for Int32.Parse .

关于c# - 如何在 C# 中将某个 string[index] 转换为 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42001743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com