无法在 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);
}

非常感谢任何帮助!

编辑:这是错误信息:http://gyazo.com/ed87941f4c8226ad6ebfd60879a5f173

首先你需要去掉数字末尾的“_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);
}