Exemple #1
0
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is hexadecimal.
 /// </summary>
 /// <param name="value">The string to verify is hexadecimal.</param>
 /// <returns><c>true</c> if the specified <paramref name="value"/> is hexadecimal; otherwise, <c>false</c>.</returns>
 public static bool IsHex(string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         return(false);
     }
     if (!NumberUtility.IsEven(value.Length))
     {
         return(false);
     }
     using (StringReader reader = new StringReader(value))
     {
         int even = value.Length / 2;
         for (int i = 0; i < even; ++i)
         {
             char char1 = (char)reader.Read();
             char char2 = (char)reader.Read();
             if (!IsHexDigit(char1) || !IsHexDigit(char2))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is an even number.
 /// </summary>
 /// <param name="value">The value to evaluate.</param>
 /// <returns><c>true</c> if the specified <paramref name="value"/> is an even number; otherwise, <c>false</c>.</returns>
 public static bool IsEven(this int value)
 {
     return(NumberUtility.IsEven(value));
 }