I have this C# code here, and what I'm trying to do is that when I put a number with many digits the application crashes and I want it to not crash but I don't know what to do, I tried changing the .Parse command but Idk which command to use instead. An example is that when I run the application I want to put a number like 564984894897987878 and I want the application to not crash, can someone help me, in this case, please? If you find a solution post it here including your code and my code too please and thank you?!
int num; Console.Write("Please type your number here:"); num = Int32.Parse(Console.ReadLine()); if (num < 0) Console.WriteLine("This is a negative number!"); if (num > 0) Console.WriteLine("This number is a positive number");
int, uselonginstead.intcan only be up to2147483647whereaslongwill get you to9223372036854775807. If you want bigger than that then look intoBigInteger.BigIntegertype that supports unlimited precision (well, as long as memory lasts anyway).System.Numerics.BigInteger.Parse("564984894897987878")works, as doesSystem.Numerics.BigInteger.Parse("123456789012345678901234567890123456789012345678901234567890"). Of course, efficiency in calculating is much lower than withint, so it really depends what you want this number for -- if all you need is astringand you want to verify it contains only digits, use something else (like"1234".All(Char.IsDigit)). If all you want to test is the sign, the first character suffices!