Casting: or Parsing
A cast explicitly invokes the conversion operator from one type to another.
Casting variables is not simple. A complicated set of rules resolves casts. In some cases data is lost and the cast cannot be reversed. In others an exception is provoked in the execution engine.
int.Parse
is a simplest method but it throws exceptions on invalid input.
TryParse
int.TryParse
is one of the most useful methods for parsing integers in the C# language. This method works the same way as int.Parse
.
int.TryParse
has try and catch structure inside. So, it does not throw exceptions
Convert:
Converts a base data type to another base data type.
Convert.ToInt32, along with its siblings Convert.ToInt16 and Convert.ToInt64, is actually a static wrapper method for the int.Parse method.
Using TryParse
instead of Convert
or Cast
is recommended by many programmers.
source:www.dotnetperls.com