A better way might be to use int.TryParse(). Try this:
Code:
string text;
int num;
do
{
Console.Write("Enter some text (no numbers): ");
text = Console.ReadLine();
} while (text.Any(c => Char.IsDigit(c)));
do
{
Console.Write("Enter a number: ");
} while (!int.TryParse(Console.ReadLine(), out num));
Console.WriteLine("The text you entered was: {0}", text);
Console.WriteLine("The number you entered was: {0}", num);
If you don't like lambdas or LINQ (you'd have to be crazy not to!) you can always make a ContainsDigit() method that looks like:
Code:
private static bool ContainsDigit(string str)
{
foreach (char c in str)
if (Char.IsDigit(c))
return true;
return false;
}
And then you just change the do/while loop to: while(ContainsDigit(text));