Is there any built-in way to convert an integer to a string (of any base) in C#?

前端 未结 6 2033
梦毁少年i
梦毁少年i 2020-12-20 20:02

Convert.ToString() only allows base values of 2, 8, 10, and 16 for some odd reason; is there some obscure way of providing any base between 2 and 16?

6条回答
  •  长情又很酷
    2020-12-20 20:17

    string foo = Convert.ToString(myint,base);
    

    http://msdn.microsoft.com/en-us/library/14kwkz77.aspx

    EDIT: My bad, this will throw an argument exception unless you pass in the specified bases (2, 8, 10, and 16)

    Your probably SOL if you want to use a different base (but why???).

提交回复
热议问题