Hi!
I am a novice in C#, I was trying hard to take simple integer as input in C# but I was having problems, so please could anybody write me a simple program through which I can take simple integer as input.
Thank u.
Hi!
I am a novice in C#, I was trying hard to take simple integer as input in C# but I was having problems, so please could anybody write me a simple program through which I can take simple integer as input.
Thank u.
Know the answer? Post it. Somebody with the same question will find it here.
David Azzopardi10 pointsPosted Jul 13, 2009, 1:01 AM EDT
Below is a small program which accepts an input by the user. The input value is then checked to verify whether it is an integer or not, and the result is displayed to the user.
using System;
class Program
{
static void Main(string[] args)
{
string input = string.Empty;
int intValue = 0;
Console.WriteLine("Insert an integer value");
input = Console.ReadLine();
if (int.TryParse(input, out intValue))
Console.WriteLine(string.Format("Integer value {0} input by user.", intValue));
else
Console.WriteLine("User did not enter an integer!");
Console.ReadLine();
}
}
Hope this helps.
Cheers
David