Search code examples
c#arraysstringargumentsuint

String[] to uint32 c#


I am trying to convert String[] args[1] to uint, but I keep getting System.FormatException, any ideas on how I can fix this?

I'm converting with this code:

uint Offset = Convert.toUInt32(args[1]);

My args[1] is 0x026C0658, but I want 0x026C0658 converted from String[], to uint.


Solution

  • Strip of the prefix (0x) and tell it to use base 16:

    var i = Convert.ToUInt32("026C0658", 16); // 40633944
    

    The array factor is separate and unrelated.