Share via


StringExtensions.AsInt Method (String)

Converts a string to an integer.

Namespace:  System.Web.WebPages
Assembly:  System.Web.WebPages (in System.Web.WebPages.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function AsInt ( _
    value As String _
) As Integer
'Usage
Dim value As String 
Dim returnValue As Integer 

returnValue = value.AsInt()
public static int AsInt(
    this string value
)
[ExtensionAttribute]
public:
static int AsInt(
    String^ value
)
static member AsInt : 
        value:string -> int
public static function AsInt(
    value : String
) : int

Parameters

Return Value

Type: System.Int32
The converted value.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.111) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.111).

Remarks

For more information about how to use this method, see the AsInt() topic. If you pass a non-numeric string value, an empty string (""), null reference (Nothing in Visual Basic), or a value outside the range of the specified type, the method returns 0. To avoid ambiguity about what the returned value means, call the IsInt(String) method first to check whether the input string can be converted to an integer value.

See Also

Reference

StringExtensions Class

AsInt Overload

System.Web.WebPages Namespace