top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How tryParse method works in C#?

+5 votes
How tryParse method works in C#?
posted Mar 9, 2014 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The int.TryParse method converts strings into ints. It never throws an exception—even on invalid input and null. It is called in a different way than int.Parse. It is overall preferable to int.Parse in most program contexts.
Note:Use int.TryParse to parse integers in most situations. This is often faster and results in simpler logic.
Note 2:This method is ideal for input that is not always correct. When errors occur, performance is better.

int quantity;
    quantity = int.Parse(txtQuantity.Text);
catch (FormatException)
    quantity = 0;
catch (OverflowException)
    quantity = 0;
answer Dec 1, 2014 by Shivaranjini
Similar Questions
+3 votes

By-default all the methods & variables in class are private.

In Main() method is private then how compiler access this Main() Method out side the class because compiler is not part of our program then how compiler access this Main() method?

Here we loose our data abstraction property ? Can anyone put some light on it?

+4 votes

Is it possible to override this method? if yes then how can we achieve it?