开发者

Does providing an IFormatProvider to byte.ToString("x2") matter?

开发者 https://www.devze.com 2022-12-27 06:01 出处:网络
If you are calling ToString on a byte to co开发者_如何学运维nvert it to a 2 digit hex value does it matter if you use a format provide of CultureInfo.CurrentCulture or CultureInfo.InvariantCulture in

If you are calling ToString on a byte to co开发者_如何学运维nvert it to a 2 digit hex value does it matter if you use a format provide of CultureInfo.CurrentCulture or CultureInfo.InvariantCulture in any way?

Example:

public string CalculateMD5Hash(string input)
{
    MD5 md5 = System.Security.Cryptography.MD5.Create();
    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    byte[] hash = md5.ComputeHash(inputBytes);

    StringBuilder sb = new StringBuilder();
    foreach (byte b in hash)
    {
        sb.Append(b.ToString("x2",CultureInfo.InvariantCulture));
    }
    return sb.ToString();
}

Basically can I leave out the IFormatProvider and always get the same result, or if I provide on of the CultureInfo defaults it will make a difference in the output?


Maybe, in the far far future we will have culturally dependent notations for Hex values. But today, no. You can safely omit the FormatProvider.

0

精彩评论

暂无评论...
验证码 换一张
取 消