<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Why you should use TryParse() in C#</title>
	<atom:link href="http://fatagnus.com/why-you-should-use-tryparse-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/</link>
	<description>One is glad to be of service</description>
	<pubDate>Fri, 12 Mar 2010 01:32:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dj Kav</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-77333</link>
		<dc:creator>Dj Kav</dc:creator>
		<pubDate>Thu, 03 Dec 2009 16:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-77333</guid>
		<description>TryParse is a much welcome and needed addition to validation.

Try/Catch is a last resort to things that can't be handled with normal code. IE, connections and timeouts or other such critical errors.

If you need to use exception handling to try and convert a String into an Int then your being lazy in your validation code.

I can generate reports on the out come of TryParse without needing the Try/Catch exception handling.

Try/Catch is expensive in resources and should only be used sparingly. Not a replacement to proper validation code.</description>
		<content:encoded><![CDATA[<p>TryParse is a much welcome and needed addition to validation.</p>
<p>Try/Catch is a last resort to things that can&#8217;t be handled with normal code. IE, connections and timeouts or other such critical errors.</p>
<p>If you need to use exception handling to try and convert a String into an Int then your being lazy in your validation code.</p>
<p>I can generate reports on the out come of TryParse without needing the Try/Catch exception handling.</p>
<p>Try/Catch is expensive in resources and should only be used sparingly. Not a replacement to proper validation code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fremus.co.za &#187; Blog Archive &#187; Understanding what the difference is between Convert.ToInt32 and Int32.Parse</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-71017</link>
		<dc:creator>Fremus.co.za &#187; Blog Archive &#187; Understanding what the difference is between Convert.ToInt32 and Int32.Parse</dc:creator>
		<pubDate>Tue, 13 Oct 2009 14:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-71017</guid>
		<description>[...] this topic I read here and here that you could also use Int32.TryParse, which will try to convert the value to an integer and [...]</description>
		<content:encoded><![CDATA[<p>[...] this topic I read here and here that you could also use Int32.TryParse, which will try to convert the value to an integer and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BluePlateSpecial</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-69880</link>
		<dc:creator>BluePlateSpecial</dc:creator>
		<pubDate>Fri, 02 Oct 2009 23:11:41 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-69880</guid>
		<description>Hopefully someone will see this and reply back even though this is an old article. I was wondering why this was happening. Given this code:

double.TryParse("34.12345", out doubleVar)

it seems that doubleVar becomes equal to 34.1234 instead of 34.12345. It seems as though TryParse (and probably Parse for that matter) cuts off some decimal places even though the type has plenty of space to hold them. This is a frustrating problem that seems like either a bug or a very bad design decision. Does anyone have any ideas on how to get TryParse to parse the string containing a number to as many decimal places as the string originally contains (and obviously as many as the type will allow)?</description>
		<content:encoded><![CDATA[<p>Hopefully someone will see this and reply back even though this is an old article. I was wondering why this was happening. Given this code:</p>
<p>double.TryParse(&#8221;34.12345&#8243;, out doubleVar)</p>
<p>it seems that doubleVar becomes equal to 34.1234 instead of 34.12345. It seems as though TryParse (and probably Parse for that matter) cuts off some decimal places even though the type has plenty of space to hold them. This is a frustrating problem that seems like either a bug or a very bad design decision. Does anyone have any ideas on how to get TryParse to parse the string containing a number to as many decimal places as the string originally contains (and obviously as many as the type will allow)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Jensen</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-56565</link>
		<dc:creator>Mike Jensen</dc:creator>
		<pubDate>Thu, 30 Jul 2009 01:40:31 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-56565</guid>
		<description>In response to Andres' 2-year-old comment.
One good reason to test the boolean result of the TryParse function is that you might not want to assign zero if the input fails to parse:  You might instead want to assign a NULL value, for example when setting a nullable database field.

Thanks for the article Mark.</description>
		<content:encoded><![CDATA[<p>In response to Andres&#8217; 2-year-old comment.<br />
One good reason to test the boolean result of the TryParse function is that you might not want to assign zero if the input fails to parse:  You might instead want to assign a NULL value, for example when setting a nullable database field.</p>
<p>Thanks for the article Mark.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Real time Project coding Standards &#171; Sailajamehra.. writes for u&#8230;</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-43665</link>
		<dc:creator>Real time Project coding Standards &#171; Sailajamehra.. writes for u&#8230;</dc:creator>
		<pubDate>Fri, 22 May 2009 06:48:33 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-43665</guid>
		<description>[...] him about it, but have a reputation to protect. Besides you could always look it up on Google to know what it is &amp; if there is any performance benefit in doing [...]</description>
		<content:encoded><![CDATA[<p>[...] him about it, but have a reputation to protect. Besides you could always look it up on Google to know what it is &amp; if there is any performance benefit in doing [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Jensen</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-39021</link>
		<dc:creator>Mark Jensen</dc:creator>
		<pubDate>Mon, 06 Apr 2009 20:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-39021</guid>
		<description>Hi Chan

I thought that the link at the bottom of my article, then one that says "Benchmark Test", kind of gave an impression of how well it performs?

anyway, if I was biased about the example then I would probably have added one more Catch to it ;P

I know that it might look like overkill and that you probably just as easily could use Exception. However, my rule of thumb is that you should only catch specific exceptions

http://fatagnus.com/back-to-basic-with-the-try-catch-statement/

The example is very simple, but it displays the usage of the function. It doesn't fit into every single context of how one would use it :)

best regards
Mark</description>
		<content:encoded><![CDATA[<p>Hi Chan</p>
<p>I thought that the link at the bottom of my article, then one that says &#8220;Benchmark Test&#8221;, kind of gave an impression of how well it performs?</p>
<p>anyway, if I was biased about the example then I would probably have added one more Catch to it ;P</p>
<p>I know that it might look like overkill and that you probably just as easily could use Exception. However, my rule of thumb is that you should only catch specific exceptions</p>
<p><a href="http://fatagnus.com/back-to-basic-with-the-try-catch-statement/" rel="nofollow">http://fatagnus.com/back-to-basic-with-the-try-catch-statement/</a></p>
<p>The example is very simple, but it displays the usage of the function. It doesn&#8217;t fit into every single context of how one would use it :)</p>
<p>best regards<br />
Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chan kun juan</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-38592</link>
		<dc:creator>chan kun juan</dc:creator>
		<pubDate>Sat, 04 Apr 2009 09:29:13 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-38592</guid>
		<description>^Ok, I had run both way in a loop 10000 times and tryParse is 175 times faster. Try Catch is an expensive process :S</description>
		<content:encoded><![CDATA[<p>^Ok, I had run both way in a loop 10000 times and tryParse is 175 times faster. Try Catch is an expensive process :S</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chan kun juan</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-38585</link>
		<dc:creator>chan kun juan</dc:creator>
		<pubDate>Sat, 04 Apr 2009 08:49:47 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-38585</guid>
		<description>Thanks for the advice! Nice comparison of 2 examples. i got some weird impression that you are rather biased to display the superiority of the latter example by making your 1st example stupid. ;p

	int quantity;
	try
	{
		quantity = txtQuantity.Text;
	}
	catch (Exception Ex)
	{
		quantity = 0;
	}

That is the revised code of your 1st example and actually same as how the 2nd example works. Now this is a fairer comparision and i will see that 2nd example isn't that miraclous.  Maybe the OUT overload's just synatic sugar, as i am unsure of the difference in performance. Maybe you can go further and demostrate the difference in performance.</description>
		<content:encoded><![CDATA[<p>Thanks for the advice! Nice comparison of 2 examples. i got some weird impression that you are rather biased to display the superiority of the latter example by making your 1st example stupid. ;p</p>
<p>	int quantity;<br />
	try<br />
	{<br />
		quantity = txtQuantity.Text;<br />
	}<br />
	catch (Exception Ex)<br />
	{<br />
		quantity = 0;<br />
	}</p>
<p>That is the revised code of your 1st example and actually same as how the 2nd example works. Now this is a fairer comparision and i will see that 2nd example isn&#8217;t that miraclous.  Maybe the OUT overload&#8217;s just synatic sugar, as i am unsure of the difference in performance. Maybe you can go further and demostrate the difference in performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-29088</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 03 Feb 2009 14:27:26 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-29088</guid>
		<description>int id = int.TryParse("200", out id) ? id : -1;</description>
		<content:encoded><![CDATA[<p>int id = int.TryParse(&#8221;200&#8243;, out id) ? id : -1;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anon</title>
		<link>http://fatagnus.com/why-you-should-use-tryparse-in-c/comment-page-1/#comment-26872</link>
		<dc:creator>anon</dc:creator>
		<pubDate>Thu, 22 Jan 2009 20:15:50 +0000</pubDate>
		<guid isPermaLink="false">http://fatagnus.com/why-you-should-tryparse-in-c/#comment-26872</guid>
		<description>int.TryParse(txtQuantity.Text, out quantity) ? quantity = 0 : quantity;

i agree with mark.
If I saw this during a review, i'd change it.

the original example is pretty close to best practice.
use TryParse in an 'if' statement...if the Parse fails you can return the default, set it to a known error value, i.e. -1, or throw an exception.

someone made the point about catching exceptions, and they're correct.
this gives you control over the exception under this particular circumstance and can aid you considerably later</description>
		<content:encoded><![CDATA[<p>int.TryParse(txtQuantity.Text, out quantity) ? quantity = 0 : quantity;</p>
<p>i agree with mark.<br />
If I saw this during a review, i&#8217;d change it.</p>
<p>the original example is pretty close to best practice.<br />
use TryParse in an &#8216;if&#8217; statement&#8230;if the Parse fails you can return the default, set it to a known error value, i.e. -1, or throw an exception.</p>
<p>someone made the point about catching exceptions, and they&#8217;re correct.<br />
this gives you control over the exception under this particular circumstance and can aid you considerably later</p>
]]></content:encoded>
	</item>
</channel>
</rss>
