[.net] How to get input of just for an integer? (C#)

Started by
4 comments, last by ShadowWolf 19 years, 9 months ago
I'm disliking Console.Read(LINE)() function right now. I'm in the process of making a Tic Tac Toe clone just so I can remember some of the stuff I have learned using C# and it's just being a bitch about every thing. Here's the C/C++ equivilent of what I'd like to do:

void DoTurn()
{
  cout << Turn << "'s turn!";
  int move;
  cin >> move
  // do some error checking...
  if (GameBoard[move])...
}
But NOOooooooo, C# only returns a string with the ReadLine() function and boxing has no effect whatsoever.
Advertisement
Something like that:
int moves = int.Parse( Console.ReadLine() );
string s = Console.ReadLine();try{    int n = Int32.Parse(s);}catch{    // s couldn't be parsed as an integer}
Damn, how could I forget the Parse() function. Thank you my good sir.
Bleh.. System.Convert.ToInt32( Console.ReadLine() );
Or just:

Int32.Parse( Console.ReadLine() );

This topic is closed to new replies.

Advertisement