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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
David AzzopardiPosted Jul 13, 2009, 5:01 AM
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