无法在 C# 中将字符串转换为 uint
Cannot convert string to uint in c#
我是 c# 的新手,出于某种原因,我的号码终生无法转换。我的代码是:
foreach(var descriptionid in test.items)
{
ulong description = Convert.ToUInt32(descriptionid.Value.descriptionid);
Console.WriteLine(description);
}
非常感谢任何帮助!
首先你需要去掉数字末尾的“_0”,比如:
string number = descriptionid.Value.descriptionid.ToString();
string[] nums = number.Split ('_');
然后编写以下代码:
ulong description = Convert.ToUInt64(nums[0]);
我不知道你的问题和错误是什么(什么是 descriptionid.Value.descriptionid ??????),但你可以这样更改你的代码:
foreach(var descriptionid in test.items)
{
//var description = Convert.ToUInt64(descriptionid.Value.descriptionid);
var description = Convert.ToUInt64(descriptionid.Value.descriptionid.Split(new char[]{'_'})[0]);
Console.WriteLine(description);
}
我是 c# 的新手,出于某种原因,我的号码终生无法转换。我的代码是:
foreach(var descriptionid in test.items)
{
ulong description = Convert.ToUInt32(descriptionid.Value.descriptionid);
Console.WriteLine(description);
}
非常感谢任何帮助!
首先你需要去掉数字末尾的“_0”,比如:
string number = descriptionid.Value.descriptionid.ToString();
string[] nums = number.Split ('_');
然后编写以下代码:
ulong description = Convert.ToUInt64(nums[0]);
我不知道你的问题和错误是什么(什么是 descriptionid.Value.descriptionid ??????),但你可以这样更改你的代码:
foreach(var descriptionid in test.items)
{
//var description = Convert.ToUInt64(descriptionid.Value.descriptionid);
var description = Convert.ToUInt64(descriptionid.Value.descriptionid.Split(new char[]{'_'})[0]);
Console.WriteLine(description);
}