Skip to main content

Here is a code snippet for checking if string is double in C#.

/// <summary>
/// Method checks if passed string is double
/// </summary>
/// <param name="text">string text for checking</param>
/// <returns>bool - if text is double return true, else return false</returns>
public bool IsDouble(string text)
{
  Double num = 0;
  bool isDouble = false;
 
  // Check for empty string.
  if (string.IsNullOrEmpty(text))
  {
    return false;
  }
 
  isDouble = Double.TryParse(text, out num);
 
  return isDouble;
}

- Advertisement -
- Advertisement -