@@ -57,19 +57,7 @@ public static string ToHexString(this byte[]? value)
5757 if ( value is null )
5858 throw new ArgumentNullException ( nameof ( value ) ) ;
5959
60- #if NET9_0_OR_GREATER
6160 return Convert . ToHexStringLower ( value ) ;
62- #else
63- return string . Create ( value . Length * 2 , value , ( span , bytes ) =>
64- {
65- for ( var i = 0 ; i < bytes . Length ; i ++ )
66- {
67- var b = bytes [ i ] ;
68- span [ i * 2 ] = s_hexChars [ b >> 4 ] ;
69- span [ i * 2 + 1 ] = s_hexChars [ b & 0xF ] ;
70- }
71- } ) ;
72- #endif
7361 }
7462
7563 /// <summary>
@@ -107,19 +95,7 @@ public static string ToHexString(this byte[]? value, bool reverse = false)
10795 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
10896 public static string ToHexString ( this ReadOnlySpan < byte > value )
10997 {
110- #if NET9_0_OR_GREATER
11198 return Convert . ToHexStringLower ( value ) ;
112- #else
113- // string.Create with ReadOnlySpan<char> not supported in NET5 or lower
114- var sb = new StringBuilder ( value . Length * 2 ) ;
115- for ( var i = 0 ; i < value . Length ; i ++ )
116- {
117- var b = value [ i ] ;
118- sb . Append ( s_hexChars [ b >> 4 ] ) ;
119- sb . Append ( s_hexChars [ b & 0xF ] ) ;
120- }
121- return sb . ToString ( ) ;
122- #endif
12399 }
124100
125101 /// <summary>
@@ -138,15 +114,7 @@ public static string ToHexString(this ReadOnlySpan<byte> value)
138114 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
139115 public static bool NotZero ( this ReadOnlySpan < byte > x )
140116 {
141- #if NET7_0_OR_GREATER
142117 return x . IndexOfAnyExcept ( ( byte ) 0 ) >= 0 ;
143- #else
144- for ( var i = 0 ; i < x . Length ; i ++ )
145- {
146- if ( x [ i ] != 0 ) return true ;
147- }
148- return false ;
149- #endif
150118 }
151119 }
152120}
0 commit comments