Java
中的 Integer.toHexString() 的 C# 等价物是什么?
使用静态方法或Int32.ToString("x")
方法String.Format("{0:x}", x)
。
请参阅示例:
using System;
using System.Globalization;
class Program
{
static void Main()
{
int x = 4067;
string s = x.ToString("x");
Console.WriteLine(s); // fe3
s = String.Format("{0:x}", x);
Console.WriteLine(s); // fe3
s = String.Format("{0:X}", x);
Console.WriteLine(s); // FE3
s = String.Format("{0:x6}", x);
Console.WriteLine(s); // 000fe3
}
}
以下内容转换为十六进制
int myInt = 222;
string hexString = myInt.ToString("x")
MSDN 链接