<?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>AllAboutASP.NET &#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>Thu, 16 Jun 2011 14:21:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Find the sum of all the multiples of 3 or 5 below or equal to 1000</title>
		<link>http://allaboutasp.net/2011/06/find-the-sum-of-all-the-multiples-of-3-or-5-below-or-equal-to-1000/</link>
		<comments>http://allaboutasp.net/2011/06/find-the-sum-of-all-the-multiples-of-3-or-5-below-or-equal-to-1000/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 14:17:20 +0000</pubDate>
		<dc:creator>Ajay Pathak</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Sum]]></category>

		<guid isPermaLink="false">http://allaboutasp.net/2011/06/find-the-sum-of-all-the-multiples-of-3-or-5-below-or-equal-to-1000/</guid>
		<description><![CDATA[To find the sum of all the multiples of 3 or 5 below or equal to 1000, first we have to find the sum of all the numbers which are divisible by 3, than sum of numbers which are divisible by 5. Once we are done with this we have to subtract the sum of [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">To find the sum of all the multiples of 3 or 5 below or equal to 1000, first we have to find the sum of all the numbers which are divisible by 3, than sum of numbers which are divisible by 5. Once we are done with this we have to subtract the sum of numbers which are divisible by 3 and 5.</p>
<p align="justify">There are two approaches to solve this problem.</p>
<ol>
<li>
<div align="justify">The first approach is to write a loop and find the numbers which are divisible by 3,5 and add them, after this subtract the numbers which are divisible by 3 and 5.</div>
</li>
<li>
<div align="justify">The other approach is to find the count of numbers which are divisible by 3,5 and 15. After this apply the arithmetic progression’s sum formula to find the sum.</div>
</li>
</ol>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.Linq;
<span style="color: blue">using </span>System.Text;

<span style="color: blue">namespace </span>ConsoleApplication2
{
  <span style="color: blue">class </span><span style="color: #2b91af">Program
  </span>{
    <span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args)
    {
      <span style="color: blue">int </span>sum = 0;
      <span style="color: blue">int </span>range = 1000;
      <span style="color: blue">int </span>Number1 = 3; <span style="color: blue">int </span>Number2 = 5;
      <span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0, j = 0; i &lt;= range; i += Number1, j += Number2)
      {
        sum += i;
        <span style="color: blue">if </span>(j &lt; range &amp;&amp; j % Number2 == 0)
        {
          sum += j;
        }
        <span style="color: blue">if </span>(i &lt;= range &amp;&amp; i % Number2 * Number1 == 0)
        {
          sum -= i;
        }

      }
      <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;\n&quot;</span>);
      <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Sum of all the multiples of 3 or 5 below or equal to 1000&quot; </span>+
      <span style="color: #a31515">&quot;using Loop &quot;  </span>+ sum);

      <span style="color: blue">int </span>Total_Number1 = range / Number1;
      <span style="color: blue">int </span>Total_Number2 = range / Number2;
      <span style="color: blue">int </span>Total_Number1AndNumber2 = range / (Number1 * Number2);

      <span style="color: blue">int </span>sumTotal_Number1 = Total_Number1 * (Number1 + Total_Number1 * Number1) / 2;
      <span style="color: blue">int </span>sumTotal_Number2 = Total_Number2 * (Number2 + Total_Number2 * Number2) / 2;
      <span style="color: blue">int </span>sumTotal_Number1andNumber2 = Total_Number1AndNumber2 * (Number2 * Number1
          + Total_Number1AndNumber2 * Number2 * Number1) / 2;
      <span style="color: blue">int </span>total = sumTotal_Number1 + sumTotal_Number2 - sumTotal_Number1andNumber2;
      <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Sum of all the multiples of 3 or 5 below or equal to 1000 &quot; </span>+
                      <span style="color: #a31515">&quot;using arithmetic progression’s sum formula  &quot; </span>+ total);

      <span style="color: #2b91af">Console</span>.ReadLine();
    }
  }
}</pre>
<p>Please post your comments if you find a better way to find the sum of numbers which are divisible by 3 or 5 and less than 1000.</p>
]]></content:encoded>
			<wfw:commentRss>http://allaboutasp.net/2011/06/find-the-sum-of-all-the-multiples-of-3-or-5-below-or-equal-to-1000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>0</slash:comments>
		</item>
	</channel>
</rss>

