Skip to content

Commit 814f27e

Browse files
author
DwGoing
committed
🦄 refactor: 调整Hex相关扩展方法实现
1 parent de09163 commit 814f27e

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/DwFramework.Core/Extensions/StringExtension.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,14 @@ public static byte[] FromBase64String(this string base64String)
180180
/// </summary>
181181
/// <param name="bytes"></param>
182182
/// <returns></returns>
183-
public static string ToHex(this byte[] bytes)
184-
{
185-
var builder = new StringBuilder();
186-
for (var i = 0; i < bytes.Length; i++)
187-
{
188-
builder.Append(bytes[i].ToString("x2"));
189-
}
190-
return builder.ToString();
191-
}
183+
public static string ToHex(this byte[] bytes) => Convert.ToHexString(bytes);
192184

193185
/// <summary>
194186
/// Hex转字节数组
195187
/// </summary>
196188
/// <param name="hexString"></param>
197189
/// <returns></returns>
198-
public static byte[] FromHex(this string hexString)
199-
{
200-
var bytes = new byte[hexString.Length / 2];
201-
for (var i = 0; i < bytes.Length; i++)
202-
{
203-
bytes[i] = (byte)Convert.ToInt32(hexString.Substring(i * 2, 2), 16);
204-
}
205-
return bytes;
206-
}
190+
public static byte[] FromHex(this string hexString) => Convert.FromHexString(hexString);
207191

208192
/// <summary>
209193
/// 是否为中文字符

0 commit comments

Comments
 (0)