-1

I'm trying to convert the first index of a string to a int but I can't. Can someone explain how to access the index of a string and convert it to an int?

string a = "5"
public static bool VerificacaoNumero(string a, int[,] tabuleiro) 
{
  int b = a[0];
  return true;
}
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
  • There is no traces of `StringBuilder` in the post... – Alexei Levenkov Mar 27 '16 at 01:25
  • (Based on sample code you are looking for [how to check if the character is an integer](http://stackoverflow.com/questions/12866214/how-to-check-if-the-character-is-an-integer) which looks like perfect duplicate to me). – Alexei Levenkov Mar 27 '16 at 01:27

2 Answers2

2

There is already a built-in .NET method to verify if a character is a digit: Char.IsDigit

string a = "5"
public static bool VerificacaoNumero(string a, int[,] tabuleiro) 
{
    return char.IsDigit(a[0]);
}
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
1

You could parse the string value to an int.

int b;
return int.TryParse(a[0], out b);

That should work for you.

Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34