TryParse

 public static int TryParse(this string input, int defaultValue)
       {
           int value;
           if (Int32.TryParse(input, out value))
           {
               return value;
           }
           return defaultValue;
       }
Example:
"2".TryParse(-1)=2;
"Xe".TryParse(-1)=-1;

Description

This method takes away the need for writing two lines for TryParse and gives users an option of returning a default number.

Details

  • Author: Avik
  • Submitted on: 6/7/2012 10:39:26 AM
  • Language: C#
  • Type: System.Int32
  • Views: 3141

Double click on the code to select all.

 

;