Search code examples
c#uint

Cannot convert string to uint in c#


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


Solution

  • 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]);