How can I know if a char is a Digit?

  • Thread starter Thread starter Guest
  • Start date Start date
try this, it might not be the best solution but it works;

public bool IsInteger(Char theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
} //IsInteger
 
Marco Martin said:
try this, it might not be the best solution but it works;

public bool IsInteger(Char theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
} //IsInteger

No it doesn't - Convert.ToInt32(char) doesn't do what you think it
does. For instance, try this:

using System;
public class Test
{
static void Main()
{
Console.WriteLine (Convert.ToInt32('A'));
}
}
 
S***T! You're right. Sorry about that.

Marco
Jon Skeet said:
No it doesn't - Convert.ToInt32(char) doesn't do what you think it
does. For instance, try this:

using System;
public class Test
{
static void Main()
{
Console.WriteLine (Convert.ToInt32('A'));
}
}
 
Back
Top