<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ASP.Net Blog &#187; Code</title>
	<atom:link href="http://allaboutasp.net/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://allaboutasp.net</link>
	<description>Your .Net Zone</description>
	<lastBuildDate>Mon, 14 Jun 2010 00:58:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Data Type Conversion in .Net</title>
		<link>http://allaboutasp.net/2009/12/data-type-conversion-in-net/</link>
		<comments>http://allaboutasp.net/2009/12/data-type-conversion-in-net/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 11:58:28 +0000</pubDate>
		<dc:creator>Ajay Pathak</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[.Net base Data type]]></category>
		<category><![CDATA[TryParse]]></category>

		<guid isPermaLink="false">http://allaboutasp.net/2009/12/data-type-conversion-in-net/</guid>
		<description><![CDATA[Some times it is required to convert data from one base data type to another base data type. The Convert Class converts a base data type to another base data type. Convert class throw a FormatException when the attempt was made to convert a String to other base data type and String value is in [...]]]></description>
			<content:encoded><![CDATA[<p>Some times it is required to convert data from one base data type to another base data type. The Convert Class converts a base data type to another base data type. Convert class throw a FormatException when the attempt was made to convert a String to other base data type and String value is in not proper format. To Handle FormatException we can use Convert class convert method inside try catch block but there is another better way of doing the same thing is to use TryParse to avoide runtime errors and eliminate the need of Try Catch block.</p>
<p>TryParse method is available for all .Net base data type including Boolean, Char, SByte, Byte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, Decimal, DateTime and String. There are two overloaded versions of TryParse method is available for each .Net base data type. </p>
<p>Boolean.Try Parse</p>
<p>Converts specified String value to equivalent Boolean Value. Return True if Conversion is successful otherwise return False.</p>
<p>Byte.TryParse</p>
<p>Converts Specified String value to equivalent Byte Value. Return True if conversion is successful otherwise return False.</p>
<p>TryParse works in the same way for other base type also.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:20e98658-84b7-40cb-a54b-b78e40195f81" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#0000ff">Dim</span> Result <span style="color:#0000ff">As</span> <span style="color:#0000ff">Boolean</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Dim</span> ByteResult <span style="color:#0000ff">As</span> <span style="color:#0000ff">Byte</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Dim</span> BooleanResult <span style="color:#0000ff">As</span> <span style="color:#0000ff">Boolean</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Dim</span> IntegerResult <span style="color:#0000ff">As</span> <span style="color:#0000ff">Integer</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Dim</span> DoubleResult <span style="color:#0000ff">As</span> <span style="color:#0000ff">Double</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Dim</span> InputString <span style="color:#0000ff">As</span> <span style="color:#0000ff">String</span> = <span style="color:#a31515">&quot;1&quot;</span></li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Result = <span style="color:#0000ff">Byte</span>.TryParse(InputString, ByteResult)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">If</span> Result = <span style="color:#0000ff">False</span> <span style="color:#0000ff">Then</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is not converted into Byte&quot;</span> &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Else</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is converted to Byte : &quot;</span> &amp; ByteResult &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">End</span> <span style="color:#0000ff">If</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;InputString = <span style="color:#a31515">&quot;True&quot;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Result = <span style="color:#0000ff">Boolean</span>.TryParse(InputString, BooleanResult)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">If</span> Result = <span style="color:#0000ff">False</span> <span style="color:#0000ff">Then</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is not converted to Boolean : &quot;</span> &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Else</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is converted to Boolean : &quot;</span> &amp; BooleanResult &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">End</span> <span style="color:#0000ff">If</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;InputString = <span style="color:#a31515">&quot;12345&quot;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Result = <span style="color:#0000ff">Integer</span>.TryParse(InputString, IntegerResult)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">If</span> Result = <span style="color:#0000ff">False</span> <span style="color:#0000ff">Then</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is not converted to Integer&quot;</span> &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Else</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is converted to Integer : &quot;</span> &amp; IntegerResult &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">End</span> <span style="color:#0000ff">If</span></li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;InputString = <span style="color:#a31515">&quot;12345.111&quot;</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Result = <span style="color:#0000ff">Double</span>.TryParse(InputString, DoubleResult)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">If</span> Result = <span style="color:#0000ff">False</span> <span style="color:#0000ff">Then</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is not converted to Double : &quot;</span> &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">Else</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(InputString &amp; <span style="color:#a31515">&quot; is converted to Double : &quot;</span> &amp; DoubleResult &amp; vbCrLf)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">End</span> <span style="color:#0000ff">If</span></li>
</ol></div>
</p></div>
</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://allaboutasp.net/2009/12/data-type-conversion-in-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
