Sitecore 5.1.1 API

MainUtil.GetInt Method (String, Int32)

Gets the integer value of a string.

[Visual Basic]
Overloads Public Shared Function GetInt( _
   ByVal value As String, _
   ByVal _default As Integer _
) As Integer
[C#]
public static int GetInt(
   string value,
   int _default
);

Parameters

value
A string that can be converted to an int.
_default
A default value.

Return Value

The integer value of a string.

Remarks

The default value is returned if the string is blank, null or is not an integer. No exception is thrown if the string is not an integer.

Example

  int i0 = MainUtil.GetInt("12", 0); // 12
  int i1 = MainUtil.GetInt("", 0); // 0
  int i2 = MainUtil.GetInt(null, 0); // 0
  int i3 = MainUtil.GetInt("123abc", 0); // 0

See Also

MainUtil Class | Sitecore Namespace | MainUtil.GetInt Overload List