<?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>Bahramov's Personal Blog &#187; C#</title>
	<atom:link href="http://www.bahramov.com/category/code-snippets/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bahramov.com</link>
	<description>Computers, databases, networks and virtualization</description>
	<lastBuildDate>Wed, 28 Apr 2010 12:24:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Matching IP Address using the Regular Expression</title>
		<link>http://www.bahramov.com/2009/10/15/matching-ip-address-using-the-regular-expression/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/10/15/matching-ip-address-using-the-regular-expression/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 20:18:21 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/10/15/matching-ip-address-using-the-regular-expression/</guid>
		<description><![CDATA[This example demonstrates the quick and simple way to match correct IP address.
MatchesDemo.zip




 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;

 namespace MatchesDemo
 {
     public partial class IPValidate : Form
     {
       [...]]]></description>
			<content:encoded><![CDATA[<p>This example demonstrates the quick and simple way to match correct IP address.</p>
<p><a target="_self" href="http://www.snippetware.com/wp-content/uploads/2009/10/MatchesDemo1.zip">MatchesDemo.zip</a></p>
<p><a href="http://www.snippetware.com/wp-content/uploads/2009/10/ipOK1.png" rel="shadowbox[post-470];player=img;" title="ipOK"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ipOK" border="0" alt="ipOK" height="167" width="427" src="http://www.snippetware.com/wp-content/uploads/2009/10/ipOK_thumb1.png" /></a></p>
<p><a href="http://www.snippetware.com/wp-content/uploads/2009/10/ipBad1.png" rel="shadowbox[post-470];player=img;" title="ipBad"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ipBad" border="0" alt="ipBad" height="168" width="427" src="http://www.snippetware.com/wp-content/uploads/2009/10/ipBad_thumb1.png" /></a></p>
<p>
<pre class="brush: csharp">
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;

 namespace MatchesDemo
 {
     public partial class IPValidate : Form
     {
         public IPValidate()
         {
             InitializeComponent();
         }

         private void btnValidate_Click(object sender, EventArgs e)
         {
             // MessageBox.Show(mtxtIPAddress.Text);

             // create a regex object
             Regex checkIP = new Regex (@&amp;quot;\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b&amp;quot;);

             // create match
             Match matchIP = checkIP.Match(mtxtIPAddress.Text);

             if (checkIP.IsMatch(mtxtIPAddress.Text))
             {
                 mtxtIPAddress.ForeColor = Color.Green;
             }
             else
                 mtxtIPAddress.ForeColor = Color.Red;
         }
     }
 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/10/15/matching-ip-address-using-the-regular-expression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple class with default and overloaded constructor</title>
		<link>http://www.bahramov.com/2009/09/28/simple-class-with-default-and-overloaded-constructor/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/09/28/simple-class-with-default-and-overloaded-constructor/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 21:03:29 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/09/28/simple-class-with-default-and-overloaded-constructor/</guid>
		<description><![CDATA[This sample demonstrates use of default constructor, overloaded constructor, method and overloaded method in C#
Create new console C# console application. 
Add the following code to Program.cs





 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
&#160;
namespace Classes_002
{
&#160;&#160;&#160;&#160;class Program
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;static void Main(string[] args)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// create new instance of the Calculate class
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Calculate calc1 = new Calculate();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;// call doCalculation method with the default Constructor
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Console.WriteLine(&#8220;default constructor: [...]]]></description>
			<content:encoded><![CDATA[<p>This sample demonstrates use of default constructor, overloaded constructor, method and overloaded method in C#</p>
<p>Create new console C# console application. </p>
<p>Add the following code to Program.cs</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:7a7bc7a5-45e6-42b2-9554-b488ed6efcec" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<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">using</span> System;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Collections.Generic;</li>
<li><span style="color:#0000ff">using</span> System.Linq;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Text;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">namespace</span> Classes_002</li>
<li>{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[] args)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// create new instance of the Calculate class</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Calculate</span> calc1 = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Calculate</span>();</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// call doCalculation method with the default Constructor</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&#8220;default constructor: &#8220;</span> + calc1.doCalculation()+<span style="color:#a31515">&#8220;&#92;r&#8221;</span>);</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// create another instance of the Calculate class</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Calculate</span> calc2 = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Calculate</span>(100);</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// call doCalculation method with the user variable passed to Constructor</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&#8220;constructor that accepted user value: &#8220;</span> + calc2.doCalculation() + <span style="color:#a31515">&#8220;&#92;r&#8221;</span>);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// create another instance of the Calculate class</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Calculate</span> calc3 = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Calculate</span>();</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// call doCalculation method and pass to variables directly to method0</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">&#8220;method that accepts two double values: &#8220;</span> + calc2.doCalculation(25.35,10.12) + <span style="color:#a31515">&#8220;&#92;r&#8221;</span>);</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Console</span>.ReadKey();</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Add new class Calculate.cs with the following code</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:1a464d1f-dc98-4e7d-a94c-fffecb6bf4d8" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2,5em; padding: 0 0 0 5px; white-space: nowrap">
<li> <span style="color:#0000ff">using</span> System;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Collections.Generic;</li>
<li><span style="color:#0000ff">using</span> System.Linq;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Text;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">namespace</span> Classes_002</li>
<li>{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">class</span> <span style="color:#2b91af">Calculate</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// declare private variable for the class</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">private</span> <span style="color:#0000ff">int</span> constantA;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// declare initial value for default Constructor</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> Calculate()</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constantA = 10;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// declare Constructor for input of user variable</span></li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> Calculate(<span style="color:#0000ff">int</span> a)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constantA = a;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#008000">// method that actually does the calculation</span></li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> doCalculation()</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">return</span> constantA / 2;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">public</span> <span style="color:#0000ff">double</span> doCalculation(<span style="color:#0000ff">double</span> val1, <span style="color:#0000ff">double</span> val2)</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li style="background: #f3f3f3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">return</span> val1*val2;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>This is a very simple example just to demonstrate how default and overloaded constructors work in C#.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/09/28/simple-class-with-default-and-overloaded-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
