- Course
- Functions C
- Function to check if a text is number
Function to check if a text is number
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a C# program that implements a function called IsNumber that receives a text parameter from the user and check if the text is a number or not.
Input
234
Output
True
Solution
using System;
public class CheckIsNumber
{
public static void Main(string[] args)
{
string text = Console.ReadLine();
Console.WriteLine(text);
}
public static bool IsNumber(string text)
{
for (int i = 0; i < text.Length; i++)
{
if ((text[i] < '0') || (text[i] > '9'))
{
return false;
}
}
return true;
}
}