Reputation: 73
i am pretty new to c# and for some reason my number wont convert for the life of me. My code is:
foreach(var descriptionid in test.items)
{
ulong description = Convert.ToUInt32(descriptionid.Value.descriptionid);
Console.WriteLine(description);
}
Any help is really appreciated!
Edit: This is the error message: http://gyazo.com/ed87941f4c8226ad6ebfd60879a5f173
Upvotes: 1
Views: 3374
Reputation: 1794
Fisrt of all you need to get rid of the "_0" that exist at the end of the number, like that:
string number = descriptionid.Value.descriptionid.ToString();
string[] nums = number.Split ('_');
And than to write the following code:
ulong description = Convert.ToUInt64(nums[0]);
Upvotes: 1
Reputation: 3138
I don't know what's your problem and error (whats descriptionid.Value.descriptionid ?????), but you can change your code like this:
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);
}
Upvotes: 0