2
Answers

Check for an Integer Value-Without Exception

Ask a question
jaguRita

jaguRita

17y
5.8k
1
Hello all,
I want to multiply a number by itself,and the number must be Integer.A program, when i get the input number as a string it wont take it as the input n it will show an error "You are not entered Integer,try with some other number".(Without use of exceptions),Is there any possiblity?
i have written one code.But it shows an exception at run time.
int number=int.parse(console.ReadLine());
if (number <= int.MaxValue && number >= int.MinValue)
{
Console.Write("\n Enter the number :");
number *= number;
Console.WriteLine(number);
}
else
{
Console.WriteLine("You are not entered Integer,try with some other number");
}
Whats wrong with my code?How will i write the code only it will accept Integers not an decimal or string.
or Some Clues to do it.I will find out the way.
As am learner i want to know the things.
Thanks.

Answers (2)