AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

StringExtensions..::..ToInteger Method

Parses the object as an integer, returning the specified default value if parsing fails. Handles enum values, strings, and other objects via ToString().

Namespace:  AdvantageCMS.Core.Common
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static int ToInteger(
	this Object s,
	int defaultValue
)

Parameters

s
Type: Object
The object to parse.
defaultValue
Type: Int32
The value to return if parsing fails.

Return Value

The parsed integer value, or defaultValue if parsing fails.

Examples


C#
string quantity = "42";
int result = quantity.ToInteger(0); // returns 42
int fallback = "abc".ToInteger(-1); // returns -1