Home c# trying to understand the methods of PARSE () and tryparse () and...

trying to understand the methods of PARSE () and tryparse () and the Class Convert

Author

Date

Category

read about these 2 methods and class on different sites. With CONVERT everything is clear, but with 2-methods related complexity and what are their differences?


Answer 1, Authority 100%

int.parse (String S) method tries to get the number from its string view, if successful returns the number, otherwise throws formatexception .

int.tryparse (String S, Out int Result) checks whether it is possible to get a number from a string. If possible, returns True and the obtained number OUT -AMER, otherwise returns false result and Default (int) Out -pameter.

This is if it is simple, other exceptions can be emitted, depending on what the string you pass.

Example of using the second method:

string s = console.ReadLine ();
if (int.tryparse (S, Out int i))
  Console.Writeline ("Number, increased by 5: {0}", I + 5);
ELSE.
  Console.Writeline ("The introduced string was not number.");

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions