What Is Tryparse in C#?

What Is Tryparse in C#?

TryParse(String, Int32) Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded.

How do you use TryParse?

How to use int. TryParse
  1. public static void Main(string[] args)
  2. {
  3. string str = "";
  4. int intStr; bool intResultTryParse = int.TryParse(str, out intStr);
  5. if (intResultTryParse == true)
  6. {
  7. Console.WriteLine(intStr);
  8. }

What does TryParse return?

TryParse is a static data conversion method that allows to convert a string value to a corresponding 32-bit signed integer value. It returns a Boolean True value for successful conversion and False in case of failed conversion.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.