Trys to casts an object to the type of the given default value. If the object cannot be cast, the default value specified will be returned. If the object is convertable to the type of the default value, the explicit conversion will be performed.
'Declaration
Public Shared Function TryCast(Of )( _
ByVal As System.Object, _
ByVal As _
) As
'Usage
Dim obj As System.Object
Dim defaultValue As
Dim value As
value = ProvidersHelper.TryCast(Of T)(obj, defaultValue)
public static TryCast<>(
System.object ,
)
public function TryCast(
: System.TObject;
:
): ; static;
public static function TryCast(
: System.Object,
:
) : ;
public: static TryCast<>(
System.Object* ,
)
public:
static TryCastgeneric<typename >
(
System.Object^ ,
)
Parameters
- obj
- The object to be cast.
- defaultValue
- The default value to be returned if the object to be cast is null or DBNull.
Type Parameters
- T
- The type of the value to be returned.
Return Value
The value of the object cast to the type of the default value.
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2