Write another function for this code using C#

Total Post:25

Points:175
C# 
C#
 1680  View(s)
Ratings:
Rate this:
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string numberIn;
            int numberOut;

            numberIn = Console.ReadLine();

            while (!int.TryParse(numberIn, out numberOut) || numberOut < 0)
            {
                Console.WriteLine("Invalid. Enter a number that's 0 or higher.");
                numberIn = Console.ReadLine();
            }
        }
    }
}
  1. Post:24

    Points:168
    Re: Write another function for this code using C#

    static void Main(string[] args)
    
        {
            string numberIn = Console.ReadLine();
            int numberOut;
            while(!IsNumeric(numberIn))
            {
                Console.WriteLine("Invalid. Enter a number that's 0 or higher.");
                numberIn = Console.ReadLine();
            }
            numberOut = int.Parse(numberIn);
        }
        private static bool IsNumeric(string num)
        {
            return num.ToCharArray().Where(x => !Char.IsDigit(x)).Count() == 0;
        }

      Modified On Mar-31-2018 06:31:36 AM

Answer