An introduction to the differences between Convert.ToInt32 of and int.Parse of in C

  • 2020-05-19 05:39:30
  • OfStack

Convert is a class that inherits from system.Object; int is a value type

Inside, Convert.ToInt32 () calls the int.Parse () method;

The Convert.ToInt32 () method converts multiple types of data to int, and returns 0 when converting null, 0 or 1 when converting bool, but an error is reported when converting an empty string ("").

int.Parse () can only convert numeric strings to int; An error is reported when converting null.

Related articles: