CSharpTest.Net
TryParse(String,Type,Object) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Utils Namespace > StringUtils Class > TryParse Method : TryParse(String,Type,Object) Method

input
type
value

Glossary Item Box

Reconstructs a type from a string that was previously obtained via StringUtils.ToString(T data)

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function TryParse( _
   ByVal input As String, _
   ByVal type As Type, _
   ByRef value As Object _
) As Boolean
C# 
public static bool TryParse( 
   string input,
   Type type,
   out object value
)

Parameters

input
type
value

Example

Library/Library.Test/TestStringUtils.cs

C#Copy Code
Assert.AreEqual("5.1", StringUtils.ToString<double>(5.1));
Assert.AreEqual("5.1", StringUtils.ToString((object)new Version(5, 1)));

int ival;
object oval;

Assert.IsTrue(StringUtils.TryParse("1", out ival));
Assert.AreEqual(1, ival);

Assert.IsTrue(StringUtils.TryParse("1", typeof(int), out oval));
Assert.AreEqual(1, oval);
VB.NETCopy Code
Assert.AreEqual("5.1", StringUtils.ToString(Of Double)(5.1))
Assert.AreEqual("5.1", StringUtils.ToString(DirectCast(New Version(5, 1), Object)))

Dim ival As Integer
Dim oval As Object

Assert.IsTrue(StringUtils.TryParse("1", ival))
Assert.AreEqual(1, ival)

Assert.IsTrue(StringUtils.TryParse("1", GetType(Integer), oval))
Assert.AreEqual(1, oval)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys