tag:blogger.com,1999:blog-58050487272596860492024-03-13T09:48:35.970+05:00hammadgr8hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5805048727259686049.post-16245379759245325712020-05-18T18:44:00.016+05:002020-06-26T17:50:38.437+05:00Extension Methods (Simple example in C# language)<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;" trbidi="on"><span style="font-size: small;"><font face="verdana">Hi Friends,</font></span></div><div style="text-align: left;" trbidi="on"><span style="font-size: small;"><font face="verdana"><div style="text-align: left;" trbidi="on"><br /></div><div style="text-align: left;" trbidi="on">After a long time I am writing something on this blog. As you can see that my first priority is to deliver my thought on very simple way which will help you to clear the concept. Today we will understand that what is the basic use of <b>Extension Methods</b> and how we create them. </div><div style="text-align: left;" trbidi="on"><br /></div><div style="text-align: left;" trbidi="on">Extension methods are used to add methods in existing classes (a custom class or framework class) without changing them or inheriting them as a new class. Extension method need to be <b>static </b>and class in which you define extension method should also be an <b>static </b>class.</div><div style="text-align: left;" trbidi="on"><br /></div><div style="text-align: left;" trbidi="on">For example in order to convert string into integer I don't want to use <b>Convert.ToInt32()</b> method as it is not much handy for a programmer. So, I need to create my own method which can be used in any string variable and it looks like the method is available in existing "string" class provided by .net framework. I will create a new static class named "Extension" then create an static method in it named <b>ToInt()</b> which will be used in any string type to convert its value into integer type.</div><div><br /></div></font></span></div><div style="text-align: left;" trbidi="on"><span style="font-family: verdana; font-size: small;">I am using </span><span style="font-family: verdana; font-size: small;">IDE - Microsoft </span><span style="font-family: verdana; font-size: small;">Visual Studio 2019.</span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">1. Open Visual Studio.</font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">2. File > New > Project.</font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">3. Create New Project by selecting "Visual C#" and selecting "Console App (.Net Framework) and click "OK" button.</font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
</div><div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;" trbidi="on"><a href="https://1.bp.blogspot.com/-y3XHj2YYoic/XsKFrqUByaI/AAAAAAAABNI/smnXrQdhypc_3xz2HpYWF1xytUdSIuRLgCK4BGAsYHg/01.png" style="text-align: center;"><font face="trebuchet" size="2"><img alt="New Project" border="0" data-original-height="547" data-original-width="957" height="229" src="https://1.bp.blogspot.com/-y3XHj2YYoic/XsKFrqUByaI/AAAAAAAABNI/smnXrQdhypc_3xz2HpYWF1xytUdSIuRLgCK4BGAsYHg/w400-h229/01.png" title="New Project" width="400" /></font></a></div></div><div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div style="text-align: left;" trbidi="on">
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: small;"><font face="verdana" size="2">4. Add a new class by right clicking on project > Add > Class.</font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: small;"><font face="verdana" size="2"><br /></font></span></div>
</div>
<div style="text-align: left;">
<div class="separator" style="clear: both; text-align: left;"><a href="https://1.bp.blogspot.com/-vuaaj1l1A5w/XsUvKlPWm6I/AAAAAAAABQw/vk18XWBMBzoZVK4NGybdNORjE59GT1pugCK4BGAsYHg/03.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="596" data-original-width="762" src="https://1.bp.blogspot.com/-vuaaj1l1A5w/XsUvKlPWm6I/AAAAAAAABQw/vk18XWBMBzoZVK4NGybdNORjE59GT1pugCK4BGAsYHg/s320/03.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">5. Name it anything for example "Extension" and click "Add" button.</font></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://1.bp.blogspot.com/-eXRiSXHLJXI/XsKLrv33wOI/AAAAAAAABOg/SKXnO7PFOesl_cn94IMzSAuugwRZQV6rgCK4BGAsYHg/04.png" style="margin-left: 1em; margin-right: 1em;"><font face="trebuchet" size="2"><img alt="Extension class" border="0" data-original-height="543" data-original-width="957" height="228" src="https://1.bp.blogspot.com/-eXRiSXHLJXI/XsKLrv33wOI/AAAAAAAABOg/SKXnO7PFOesl_cn94IMzSAuugwRZQV6rgCK4BGAsYHg/w400-h228/04.png" title="Extension class" width="400" /></font></a></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">6. Extension class should be static. </font></span></div>
</div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">7. Add following method in this class:</font></span></div>
<div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div style="text-align: left;">
<span style="font-family: "courier new", courier, monospace; font-size: xx-small;"><font face="courier" size="2"><span style="color: #3367d6;">public static int</span> ToInt(<span style="color: #3367d6;">this string </span>Value)</font></span></div>
<div style="text-align: left;">
<span style="font-family: "courier new", courier, monospace; font-size: xx-small;"><font face="courier" size="2">{</font></span></div>
<div style="text-align: left;">
<span style="font-family: "courier new", courier, monospace; font-size: xx-small;"><font face="courier" size="2"><span style="color: #3367d6;"> int</span>.TryParse(Value, <span style="color: #3367d6;">out int </span>result);</font></span></div>
<div style="text-align: left;">
<span style="font-family: "courier new", courier, monospace; font-size: xx-small;"><font face="courier" size="2"><span style="color: #3367d6;"> return </span>result;</font></span></div>
<div style="text-align: left;">
<span style="font-family: "courier new", courier, monospace; font-size: xx-small;"><font face="courier" size="2">}</font></span></div>
</div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">it will look like this:<b> (note that the class should be static).</b></font></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><b><font face="trebuchet" size="2"><br /></font></b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://1.bp.blogspot.com/-mn648aQKeIA/XsKL7mZWqYI/AAAAAAAABO0/KJlyjacz2zQrVivAKqK7Xc1ULjJanSEcgCK4BGAsYHg/05.png" style="margin-left: 1em; margin-right: 1em;"><font face="trebuchet" size="2"><img alt="Extension class with code" border="0" data-original-height="386" data-original-width="619" height="250" src="https://1.bp.blogspot.com/-mn648aQKeIA/XsKL7mZWqYI/AAAAAAAABO0/KJlyjacz2zQrVivAKqK7Xc1ULjJanSEcgCK4BGAsYHg/w400-h250/05.png" title="Extension class with code" width="400" /></font></a></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">8. Then add following code into <b>Main()</b> method of Program class:</font></span></div>
</div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
</div>
<div style="text-align: left;">
<div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace;"><font face="courier" size="2"><span style="color: #3367d6;">string </span>stringYear = <span style="color: #e67c73;">"2020"</span>;</font></span></div>
</div>
</div>
<div style="text-align: left;">
<div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace;"><font face="courier" size="2"><span style="color: #0b8043;">Console</span>.WriteLine(stringYear.GetType() + <span style="color: #e67c73;">" - "</span> + stringYear);</font></span></div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace; font-size: small;"><font face="courier" size="2"><br /></font></span></div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace; font-size: small;"><font face="courier" size="2"><span style="color: #3367d6;">int </span>intYear = stringYear.ToInt();</font></span></div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace;"><font face="courier" size="2"><span style="color: #0b8043;">Console</span>.WriteLine(intYear.GetType() + <span style="color: #e67c73;">" - "</span> + intYear);</font></span></div>
<div style="text-align: left;">
<span style="background-color: white; font-family: "courier new", courier, monospace;"><font face="courier" size="2"><span style="color: #0b8043;">Console</span>.Read();</font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">It will look like this:</font></span></div>
</div>
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://1.bp.blogspot.com/-tFXxDAHK57c/XsKMfrfm0TI/AAAAAAAABPQ/KSCQ8sPvJsocVIqOZhu8y-bwcUYHlR9zwCK4BGAsYHg/06.png" style="margin-left: 1em; margin-right: 1em;"><font face="trebuchet" size="2"><img alt="Program class with code" border="0" data-original-height="467" data-original-width="814" height="230" src="https://1.bp.blogspot.com/-tFXxDAHK57c/XsKMfrfm0TI/AAAAAAAABPQ/KSCQ8sPvJsocVIqOZhu8y-bwcUYHlR9zwCK4BGAsYHg/w400-h230/06.png" title="Program class with code" width="400" /></font></a></div>
</div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">9. Press F5 to execute the program, you will see the following output:</font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;"><a href="https://1.bp.blogspot.com/-AG-fgTezSus/XsUvsEojRTI/AAAAAAAABRA/7J5YZ5-N0y8gwagAxrkV-oS7Td747y4HQCK4BGAsYHg/07.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="158" data-original-width="453" src="https://1.bp.blogspot.com/-AG-fgTezSus/XsUvsEojRTI/AAAAAAAABRA/7J5YZ5-N0y8gwagAxrkV-oS7Td747y4HQCK4BGAsYHg/s320/07.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="trebuchet" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">Which shows that the code is working fine and now with the help of extension method, you can use our newly created <b>ToInt()</b> method </font></span><span style="font-family: verdana; font-size: small;">by just pressing "." dot after any string variable.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><span style="font-family: verdana; font-size: small;">There are a lot more complex examples than this but t</span><font face="verdana" size="2">his was the simplest example by which I can demonstrate you the basic use of extension methods. </font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">Please feel free to ask anything regarding this on my provided contact details.</font></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div><div class="separator" style="clear: both; text-align: left;"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; text-align: left;"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; text-align: left;"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; text-align: left;"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">My Youtube channel:</div><div class="separator" style="clear: both; text-align: left;"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2"><br /></font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">Thanks</font></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif; font-size: xx-small;"><font face="verdana" size="2">Have a nice day!</font></span></div>
</div>
hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-81950975366057648292012-06-03T09:09:00.001+05:002020-06-26T17:50:58.707+05:00How To Read XML Data into DataSet by Using C# .NET<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
</h2>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif;">During my past experience i have worked on complex xml logics and learned a lot of depth knowledge that how xml data can be integrated into Dot Net application. So, i want to share a very basic knowledge about xml integration.</span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif;">The first step to integrate xml is to Read XML file and get data from it, so that the existing application can work on that data. I am sharing a basic tutorial which will guide you to start working on xml by showing you how to read data from it.</span></div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;">I tried to create a simple User Interface. (isn't it) :)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-9tLlrAP9ylE/T8rZlSd4TJI/AAAAAAAAAIs/g0Q7nuoGdV0/s1600/01.JPG" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "trebuchet ms", sans-serif;"><img border="0" height="292" src="http://3.bp.blogspot.com/-9tLlrAP9ylE/T8rZlSd4TJI/AAAAAAAAAIs/g0Q7nuoGdV0/s320/01.JPG" width="320" /></span></a></div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;">By clicking on Browse button, a file dialogue will open just select an xml file (Note: this dialogue will only allow you to select *.xml files) and i will show you that how this useful feature can be utilised in our application to filter files in OpenFileDialog control.</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;">When you select an xml file, this simple application will open this xml into the below Data Grid View Control (Like this):</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-hbA80a5PIds/T8rcL2vlnFI/AAAAAAAAAI4/idc8bGlf_UI/s1600/02.JPG" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "trebuchet ms", sans-serif;"><img border="0" height="291" src="http://2.bp.blogspot.com/-hbA80a5PIds/T8rcL2vlnFI/AAAAAAAAAI4/idc8bGlf_UI/s320/02.JPG" width="320" /></span></a></div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;">The very simple code behind of this application is following:</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<br />
<br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Collections.Generic;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.ComponentModel;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Data;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Drawing;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Text;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Windows.Forms;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">namespace</span> XmlViewer</span><br />
<span style="font-family: "trebuchet ms", sans-serif;">{</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">public</span> partial class <span style="color: #3d85c6;">Form1 </span>: <span style="color: #3d85c6;">Form</span></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">public </span>Form1()</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> InitializeComponent();</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">private void </span>btnBrowse_Click(<span style="color: blue;">object </span>sender, EventArgs e)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">try</span></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> ShowXmlData();</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">catch </span>(<span style="color: #3d85c6;">Exception </span>ex)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: #3d85c6;">MessageBox</span>.Show(ex.Message);</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">private void </span>ShowXmlData()</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: #38761d;"> //IT WILL SHOW THE DIALOG BOX FOR BROWSING XML FILE</span></span><br />
<span style="color: #38761d; font-family: "trebuchet ms", sans-serif;"> //AND SAVING THEN SHOW IT TO TEXTBOX</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> openFileDialog1.ShowDialog();</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> txtFilePath.Text = openFileDialog1.FileName;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">if </span>(ValidateFileName(txtFilePath.Text))</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: #38761d;"> //IT WILL READ DATA FROM SELECTED XML</span></span><br />
<span style="color: #38761d; font-family: "trebuchet ms", sans-serif;"> //AND SHOW IT TO DATA GRID VIEW CONTROL</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: #3d85c6;">DataSet </span>ds = new <span style="color: #3d85c6;">DataSet</span>();</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> ds.ReadXml(txtFilePath.Text);</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> dgvXmlData.DataSource = ds.Tables[0];</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">else</span></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">throw new</span> <span style="color: #3d85c6;">Exception</span>(<span style="color: #741b47;">"Invalid Data"</span>);</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">private bool</span> ValidateFileName(<span style="color: blue;">string </span>fileName)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: #38761d;"> //YOU CAN WRITE YOUR OWN LOGIC HERE</span></span><br />
<span style="color: #38761d; font-family: "trebuchet ms", sans-serif;"> //TO FILTER FURTHER</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">if </span>(fileName != <span style="color: #741b47;">""</span>)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">return true</span>;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">else</span></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">return false</span>;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;">}</span><br />
<div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms", sans-serif;">How to restrict OpenFileDialog for *.xml files:</span></h3>
<div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-qbuh7vSjzMU/T8rhIQhTA3I/AAAAAAAAAJE/fxLKu_-TGMw/s1600/04.bmp" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "trebuchet ms", sans-serif;"><img border="0" height="400" src="http://3.bp.blogspot.com/-qbuh7vSjzMU/T8rhIQhTA3I/AAAAAAAAAJE/fxLKu_-TGMw/s400/04.bmp" width="215" /></span></a></div>
<div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div>
<ol style="text-align: left;">
<li><span style="font-family: "trebuchet ms", sans-serif;">Select OpenFileDialog from Form and View the Properties.</span></li>
<li><span style="font-family: "trebuchet ms", sans-serif;">Select "Filter" field.</span></li>
<li><span style="font-family: "trebuchet ms", sans-serif;">Type "xml files|*.xml".</span></li>
</ol>
<div>
<span style="font-family: "trebuchet ms", sans-serif;">You can use this option to filter any type of file e.g. (*.txt, *.doc, *.wav etc.).</span></div>
</div>
<div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms", sans-serif;">Hope this post if useful for you, If you have any question or suggestion then please contact me.</span></div>
<br /></div><div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both;"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both;"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both;"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both;"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">My Youtube channel:</div><div class="separator" style="clear: both;"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-34386016640504653962011-05-27T16:02:00.005+05:002020-06-26T17:51:18.615+05:00Constructor Sequence<div dir="ltr" style="text-align: left;" trbidi="on"><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;">This sample code will ease your understanding about constructor that when constructor is called.</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><br />
</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;">using System;</span><br />
<span style="font-size: small;">using System.Collections.Generic;</span><br />
<span style="font-size: small;">using System.Linq;</span><br />
<span style="font-size: small;">using System.Text;</span><br />
<span style="font-size: small;"><br />
</span><br />
<span style="font-size: small;">namespace ConstructorSequence</span><br />
<span style="font-size: small;">{</span><br />
<span style="font-size: small;"> class One</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> public One()</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> Console.WriteLine("</span><span style="color: blue; font-size: small;">Constructor of class One</span><span style="font-size: small;">");</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"><br />
</span><br />
<span style="font-size: small;"> static void Main(string[] args)</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> Console.WriteLine("</span><span style="color: blue; font-size: small;">Begin Main Method</span><span style="font-size: small;">");</span><br />
<span style="font-size: small;"> Two t = new Two();</span><br />
<span style="font-size: small;"> Console.WriteLine("</span><span style="color: blue; font-size: small;">End Main Method</span><span style="font-size: small;">");</span><br />
<span style="font-size: small;"> Console.Read();</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"><br />
</span><br />
<span style="font-size: small;"> class Two : One</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> public Two()</span><br />
<span style="font-size: small;"> {</span><br />
<span style="font-size: small;"> Console.WriteLine("</span><span style="color: blue; font-size: small;">Constructor of class Two</span><span style="font-size: small;">");</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;"> }</span><br />
<span style="font-size: small;">}</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><br />
</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;">Output will be:</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><br />
</span></div><div class="separator" style="clear: both; font-family: "trebuchet ms", sans-serif; text-align: center;"><span style="font-size: small;"><a href="http://2.bp.blogspot.com/-Bt0ZD6zTtvQ/Td9_Zb4OKYI/AAAAAAAAABY/94b2D0NAjw4/s1600/ConstructorSequence.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-Bt0ZD6zTtvQ/Td9_Zb4OKYI/AAAAAAAAABY/94b2D0NAjw4/s1600/ConstructorSequence.jpg" /></a></span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><br />
</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;">As you can observed that:</span></div><ol style="font-family: "trebuchet ms", sans-serif; text-align: left;"><li><span style="font-size: small;">First, Main() method will be run and according to first line of this method, result will be "</span><span style="color: blue; font-size: small;">Begin Main Method</span><span style="font-size: small;">".</span></li>
<li><span style="font-size: small;">Second line of Main() method will going to create object of Class Two by the statement "Two t = new Two();".</span></li>
<li><span style="font-size: small;">Remember, whenever new object has going to create the following three things will be done:</span></li>
<ol><li><span style="font-size: small;">Constructor of the class for which an object creation is requested will called.</span></li>
<li><span style="font-size: small;">Memory space will be consumed to store that object.</span></li>
<li><span style="font-size: small;">Return the reference of that object to do any thing in future with this object.</span></li>
</ol><li><span style="font-size: small;">As per above knowledge base, the constructor of class Two will be called and again Remember one thing that before going into the body of called constructor while creating object there is one thing which is implicitly defined i.e. "Calling of Base/Parent Class constructor". This is called containment.</span></li>
<li><span style="font-size: small;">So, before going to the line "Console.WriteLine("Constructor of class Two");" constructor of Class One will be called and which resulted "</span><span style="color: blue; font-size: small;">Constructor of class One</span><span style="font-size: small;">".</span></li>
<li><span style="font-size: small;">After this, actual code of Class Two's constructor will be run and resulted "</span><span style="color: blue; font-size: small;">Constructor of class Two</span><span style="font-size: small;">".</span></li>
<li><span style="font-size: small;">Now above mentioned three steps for creating object has been performed and its time to leave the line "Two t = new Two();". So, next printed line will be "</span><span style="color: blue; font-size: small;">End Main Method</span><span style="font-size: small;">".</span></li>
</ol><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;">If you have any question regarding this flow contact me i will try my level best to help you. </span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><br /></span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman"; font-size: medium;"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com1tag:blogger.com,1999:blog-5805048727259686049.post-49278035715021734502011-05-27T13:03:00.005+05:002020-06-26T17:51:33.964+05:00Method Overloading from Inherited Class<div dir="ltr" style="text-align: left;" trbidi="on"><div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: large;"><b>Method Overloading from Inherited Class</b></span></div><div style="font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="font-family: "trebuchet ms", sans-serif;">Method overloading is one of the best essence of Object Oriented Programming which made this dish very tasty for Programmers. And this is going to help you for making your overloading concept very clear if you have a confusion about overloading in inheritance.<br />
<br />
This is very basic example but hopefully it will going to help you to understand the concept of overloading of a parent class method in child class.</div><div style="font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="font-family: "trebuchet ms", sans-serif;">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
namespace Overloading<br />
{<br />
class One<br />
{<br />
static void Main(string[] args)<br />
{<br />
Console.WriteLine("Begin Main Method");<br />
Two t = new Two();<br />
t.overload();<br />
t.overload(0);<br />
Console.WriteLine("End Main Method");<br />
Console.Read();<br />
}<br />
<br />
public void overload()<br />
{<br />
Console.WriteLine("Method of class One");<br />
}<br />
}<br />
<br />
class Two : One<br />
{<br />
public void overload(int number)<br />
{<br />
Console.WriteLine("Method of class Two");<br />
}<br />
}<br />
}<br />
<br />
<b><span style="font-size: large;">Output will be:</span></b><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Tbv9-uk52vE/Td9vru0TVBI/AAAAAAAAABU/IpIwjDvnF0c/s1600/Overloading.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-Tbv9-uk52vE/Td9vru0TVBI/AAAAAAAAABU/IpIwjDvnF0c/s1600/Overloading.jpg" /> </a></div><div class="separator" style="clear: both; text-align: left;">If you found this post helpful or it can be more helpful by adding something else, so your response will be appreciated. Help me to help you.</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-29124530065954499912010-10-22T01:25:00.001+05:002011-06-01T18:09:03.748+05:00Efficiency means<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: center;"><blockquote><span style="font-family: "Trebuchet MS",sans-serif; font-size: large;">“Efficiency is doing things right; effectiveness is doing the right things.”</span> </blockquote><br />
<blockquote><i><span style="font-family: "Trebuchet MS",sans-serif;">[</span></i><i style="font-family: "Trebuchet MS",sans-serif;">by Peter F. Drucker</i><i><span style="font-family: "Trebuchet MS",sans-serif;">]</span></i></blockquote><span style="font-family: Arial,Helvetica,sans-serif;">Are you following this?</span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-63866031497816251402010-06-29T14:51:00.007+05:002020-06-26T17:51:52.778+05:00Check whether date is valid or not<div class="separator" style="clear: both; font-family: "trebuchet ms", sans-serif; text-align: center;"><a href="http://3.bp.blogspot.com/_Qltbf0plbw4/TCnEVl-0bKI/AAAAAAAAAA4/6ujYYgKJQfc/s1600/untitled.bmp" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://3.bp.blogspot.com/_Qltbf0plbw4/TCnEVl-0bKI/AAAAAAAAAA4/6ujYYgKJQfc/s320/untitled.bmp" width="320" /></a></div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Data;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Configuration;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Collections;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web.Security;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web.UI;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web.UI.WebControls;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web.UI.WebControls.WebParts;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">using System.Web.UI.HtmlControls;</div><div style="color: black; font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">public partial class ApplyNow : System.Web.UI.Page<br />
{<br />
private String dob;<br />
<br />
</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">protected void btn_applyNow_Click(object sender, EventArgs e)<br />
{<br />
if (getDob())<br />
{<br />
if (isAvailable(txt_emailAddress.Text))<br />
insertStudent();<br />
<br />
else<br />
lbl_error.Text = "Email already exists";<br />
}<br />
<br />
else<br />
{<br />
lbl_error.Text = "Please enter valid date";<br />
}<br />
}</div><div style="color: black; font-family: "trebuchet ms", sans-serif;"></div><div style="color: black; font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="color: black; font-family: "trebuchet ms", sans-serif;">private bool getDob()<br />
{<br />
dob = ddl_month.SelectedValue + " " + ddl_day.SelectedValue + ", " + <br />
ddl_year.SelectedValue;<br />
<br />
try<br />
{<br />
DateTime.Parse(dob);<br />
return true;<br />
}<br />
<br />
catch<br />
{<br />
return false;<br />
}<br />
}</div><div style="color: black; font-family: "trebuchet ms", sans-serif;"></div><div style="color: black; font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="color: black; font-family: "trebuchet ms", sans-serif;"> private void insertStudent()<br />
{</div><div style="color: black; font-family: "trebuchet ms", sans-serif;"> //coding </div><div style="color: black; font-family: "trebuchet ms", sans-serif;"> }<br />
} </div><div style="color: black; font-family: "trebuchet ms", sans-serif;"><br /></div><div style="color: black; font-family: "trebuchet ms", sans-serif;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div><div style="font-family: "trebuchet ms", sans-serif;"><span id="goog_333890639"></span><span id="goog_333890640"></span></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com1tag:blogger.com,1999:blog-5805048727259686049.post-52740539068712728612010-06-24T20:27:00.003+05:002020-06-26T17:52:04.168+05:00C# Dynamic DropDownList of Year<span style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">private void </span>fillDropdown()</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">int </span>year = <span style="color: #6fa8dc;">DateTime</span>.Now.Year;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> year -= 1;</span><br />
<br />
<span style="font-family: "trebuchet ms", sans-serif;"> <span style="color: blue;">for </span>(<span style="color: blue;">int </span>i = 0; i <= 100; i++)</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> {</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> ddl_year.Items.Add(year.ToString());</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> year--;</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"> }</span><div><span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div><div><span style="font-family: "trebuchet ms", sans-serif;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></span></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-41943764786169181882010-06-05T19:06:00.003+05:002020-06-26T17:52:15.097+05:00Get Internal IP of machine in C#<div style="font-family: "trebuchet ms", sans-serif;"><span style="color: #38761d;">//other related namespaces </span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">using</span> System.Net;</div><div style="font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="font-family: "trebuchet ms", sans-serif;"><span style="color: #38761d;">//this is example class, you can code it in your own way </span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="color: blue;">public class</span> <span style="color: #76a5af;">getIP</span> : System.Web.UI.<span style="color: #76a5af;">Page</span><br />
{</div><div style="font-family: "trebuchet ms", sans-serif;"><span style="color: #38761d;"> //other related coding</span></div><div style="font-family: "trebuchet ms", sans-serif;"><span style="color: #76a5af;"> IPHostEntry</span> IPHost = <span style="color: #76a5af;">Dns</span>.GetHostEntry(<span style="color: #76a5af;">Dns</span>.GetHostName());<br />
String ip = IPHost.AddressList[0].ToString();</div><div style="font-family: "trebuchet ms", sans-serif;"></div><div style="font-family: "trebuchet ms", sans-serif;">}</div><div style="font-family: "trebuchet ms", sans-serif;"><br /></div><div style="font-family: "trebuchet ms", sans-serif;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-20126142695252455762010-06-03T12:56:00.005+05:002020-06-26T17:52:25.035+05:00SQL Server: Insert records from .txt file<span style="font-family: "trebuchet ms", sans-serif; font-size: small;"></span><br />
<div style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: small;"><span style="color: blue;">CREATE TABLE</span> geoip (<br />
start_ip<span style="color: blue;"> CHAR</span>(15) NOT NULL,<br />
end_ip <span style="color: blue;">CHAR</span>(15) NOT NULL,<br />
start_long <span style="color: blue;">INT </span>NOT NULL,<br />
end_long <span style="color: blue;">INT </span>NOT NULL,<br />
country_code <span style="color: blue;">CHAR</span>(2) NOT NULL,<br />
country_name <span style="color: blue;">VARCHAR</span>(50) NOT NULL);<br />
<br />
<br />
<span style="color: blue;">BULK INSERT</span> geoip<br />
<span style="color: blue;"> FROM </span><span style="color: red;">'d:\geoip.txt'</span><br />
<span style="color: blue;"> WITH</span><br />
(<br />
FIELDTERMINATOR =<span style="color: red;"> ','</span>,<br />
ROWTERMINATOR = <span style="color: red;">'\n'</span><br />
)</span><br />
<br />
<br />
<span style="font-size: small;">Download 'geoip.txt' <a href="http://www.box.net/shared/eonl3mcpli">here</a></span></div><div style="font-family: "trebuchet ms", sans-serif;"><br /></div><div style="font-family: "trebuchet ms", sans-serif;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-46182486309394954282010-05-12T12:44:00.002+05:002020-06-26T17:52:39.569+05:00Using the Dynamic Keyword in C# 4.0<h1 style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: x-small;">C# 4 provides a new dynamic keyword that enables dynamic typing in what has traditionally been a strongly typed language. </span></h1><h1 style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: x-small;">According to Dino Esposito's Article:</span> </h1><h1 style="font-family: "trebuchet ms", sans-serif;"><span style="font-size: x-small;"><span style="font-size: large;"><b>Dino Esposito</b> </span><i>is the author of the upcoming “Programming ASP.NET MVC” from Microsoft Press and coauthor of “Microsoft .NET: Architecting Applications for the Enterprise” (Microsoft Press, 2008). Esposito, who is based in Italy, is a frequent speaker at industry events worldwide. You can join his blog at <a href="http://weblogs.asp.net/despos" id="ctl00_MTContentSelector1_mainContentContainer_ctl06" linkindex="41" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00|ctl00_MTContentSelector1_mainContentContainer_ctl06',this);">weblogs.asp.net/despos</a>.</i></span></h1><h1 style="font-family: "trebuchet ms", sans-serif;">Using the Dynamic Keyword in C# 4.0</h1><h3 style="font-family: "trebuchet ms", sans-serif;"><a href="http://msdn.microsoft.com/magazine/ee532098.aspx?sdmr=DinoEsposito&sdmi=authors" id="ctl00_MTContentSelector1_mainContentContainer_ctl01" linkindex="42" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00|ctl00_MTContentSelector1_mainContentContainer_ctl01',this);">Dino Esposito</a></h3><div style="font-family: "trebuchet ms", sans-serif;"><img align="Left" alt="Dino Esposito" src="http://i.msdn.microsoft.com/ee336309.dino_esposito_headshot%28en-us%29.png" style="float: left; margin: 0pt 1em 0.5em 0pt;" title="Dino Esposito" />The introduction of static type checking represented an important milestone in the history of programming languages. In the 1970s, languages such as Pascal and C started enforcing static types and strong type checking. With static type checking, the compiler will produce an error for any call that fails to pass a method argument of the appropriate type. Likewise, you should expect a compiler error if you attempt to call a missing method on a type instance.</div><div style="font-family: "trebuchet ms", sans-serif;">Other languages that push forward the opposite approach—dynamic type checking—have come along over the years. Dynamic type checking contradicts the idea that the type of a variable has to be statically determined at compile time and can never change while the variable is in scope. Note, however, that dynamic type checking doesn’t confer wholesale freedom to mix types, pretending they’re the same. For example, even with dynamic type checking, you still can’t add a Boolean value to an integer. The difference with dynamic type checking is that the check occurs when the program executes rather than when it compiles.</div><h2 style="font-family: "trebuchet ms", sans-serif;">Statically Typed or Dynamically Typed</h2><div style="font-family: "trebuchet ms", sans-serif;">Visual Studio 2010 and C# 4.0 provide a new keyword, dynamic, that enables dynamic typing in what has traditionally been a statically typed language. Before diving into the dynamic aspects of C# 4.0, though, we need to get some basic terminology down.</div><div style="font-family: "trebuchet ms", sans-serif;">Let’s define a variable as a storage location that’s restricted to values of a particular type. Next, let’s specify four fundamental properties of a statically typed language:</div><ul style="font-family: "trebuchet ms", sans-serif;"><li>Every expression is of a type known at compile time.</li>
<li>Variables are restricted to a type known at compile time.</li>
<li>The compiler guarantees that type restrictions on assignments of expressions into variables meet the restrictions on the variables.</li>
<li>Semantic analysis tasks, such as overload resolution, occur at compile time and the results are baked into the assembly.</li>
</ul><div style="font-family: "trebuchet ms", sans-serif;">A dynamic language has the opposite properties. Not every expression is of a known type at compile time, nor is every variable. Storage restrictions, if any, are checked at run time and ignored at compile time. Semantic analysis occurs only at run time.</div><div style="font-family: "trebuchet ms", sans-serif;">A statically typed language does let you make some operations dynamic. The cast operator exists so you can attempt a type conversion as a runtime operation. The conversion is part of the program code, and you can summarize the semantic expressed by the cast operator as “dynamically check the validity of this conversion at run time.”</div><div style="font-family: "trebuchet ms", sans-serif;">However, concerning attributes such as dynamic and static (or perhaps strong and weak): Today they’re better applied to individual features of a programming language than to the language as a whole.</div><div style="font-family: "trebuchet ms", sans-serif;">Let’s briefly consider Python and PHP. Both are dynamic languages, let you use variables, and allow the runtime environment to figure out the actual type stored in it. But with PHP you can store, say, integers and strings in the same variable in the same scope. In this regard, PHP (like JavaScript) is a weakly typed, dynamic language.</div><div style="font-family: "trebuchet ms", sans-serif;">On the other hand, Python gives you only one chance to set the type of a variable, which makes it more strongly typed. You can dynamically assign the type to a variable and have the runtime infer it from the assigned value. After that, though, you’re not allowed to store any value of an inappropriate type in that variable.</div><h2 style="font-family: "trebuchet ms", sans-serif;">Dynamic Types in C#</h2><div style="font-family: "trebuchet ms", sans-serif;">C# 4.0 has features that make it both dynamic and static, as well as both weakly and strongly typed. Though born as a statically typed language, C# becomes dynamically typed in any context in which you use the dynamic keyword, such as this:</div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl02" style="font-family: "trebuchet ms", sans-serif;"> </span><br />
<div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl02_"><div class="CodeSnippetTitleBar"><div class="CodeDisplayLanguage"></div></div><div dir="ltr" style="background-color: #dddddd;"><pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl02_code" space="preserve"><span id="ctl00_MTContentSelector1_mainContentContainer_ctl02" style="font-family: "trebuchet ms", sans-serif;">dynamic number = 10;
Console.WriteLine(number);</span></pre></div></div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl02" style="font-family: "trebuchet ms", sans-serif;"></span><br />
<div style="font-family: "trebuchet ms", sans-serif;">And because dynamic is a contextual keyword, not a reserved one, this still holds if you have existing variables or methods named dynamic.</div><div style="font-family: "trebuchet ms", sans-serif;">Note that C# 4.0 doesn’t force you to use dynamic, in the same way that C# 3.0 didn’t force you to use var, lambdas or object initializers. C# 4.0 provides the new dynamic keyword specifically to make a few well-known scenarios easier to deal with. The language remains essentially statically typed, even though it has added the ability to interact in a more effective way with dynamic objects.</div><div style="font-family: "trebuchet ms", sans-serif;">Why would you want to use a dynamic object? First, you may not know the type of the object you’re dealing with. You may have clues but not the certainty to statically type a given variable—which is just what happens in many common situations, such as when you work with COM objects, or when you use reflection to grab instances. In this context, the dynamic keyword makes some situations less painful to deal with. Code written with dynamic is easier to read and write, making for an application that’s easier to understand and maintain.</div><div style="font-family: "trebuchet ms", sans-serif;">Second, your object may have an inherently changing nature. You may be working with objects created in dynamic programming environments such as IronPython and IronRuby. But you can also use this functionality with HTML DOM objects (subject to expando properties) and the Microsoft .NET Framework 4 objects specifically created to have dynamic natures.</div><h2 style="font-family: "trebuchet ms", sans-serif;">Using dynamic</h2><div style="font-family: "trebuchet ms", sans-serif;">It’s important to understand the concept that in the C# type system, dynamic is a type. It has a very special meaning, but it’s definitely a type and it’s important to treat it as such. You can indicate dynamic as the type of a variable you declare, the type of items in a collection or the return value of a method. You can also use dynamic as the type of a method parameter. Conversely, you can’t use dynamic with the typeof operator and you can’t use it as the base type of a class.</div><div style="font-family: "trebuchet ms", sans-serif;">The following code shows how to declare a dynamic variable in the body of a method:</div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl03" style="font-family: "trebuchet ms", sans-serif;"> </span><br />
<div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl03_"><div class="CodeSnippetTitleBar"><div class="CodeDisplayLanguage"></div></div><div dir="ltr" style="background-color: #dddddd;"><pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl03_code" space="preserve"><span id="ctl00_MTContentSelector1_mainContentContainer_ctl03" style="font-family: "trebuchet ms", sans-serif;">public void Execute() {
dynamic calc = GetCalculator();
int result = calc.Sum(1, 1);
}</span></pre></div></div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl03" style="font-family: "trebuchet ms", sans-serif;"></span><br />
<div style="font-family: "trebuchet ms", sans-serif;">If you know enough about the type of the object being returned by the GetCalculator method, you can declare the variable calc of that type, or you can declare the variable as var, letting the compiler figure out the exact details. But using var or an explicit static type would require you to be certain that a method Sum exists on the contract exposed by the type GetCalculator returns. If the method doesn’t exist, you get a compiler error.</div><div style="font-family: "trebuchet ms", sans-serif;">With dynamic, you delay any decision about the correctness of the expression at execution time. The code compiles and is resolved at run time as long as a method Sum is available on the type stored in the variable calc.</div><div style="font-family: "trebuchet ms", sans-serif;">You can also use the keyword to define a property on a class. In doing so, you can decorate the member with any visibility modifier you like, such as public, protected, and even static.</div><div style="font-family: "trebuchet ms", sans-serif;"><b>Figure 1 </b>shows the versatility of the dynamic keyword. In the main program I have a dynamic variable instantiated with the return value of a function call. That would be no big deal if it weren’t for the fact that the function receives and returns a dynamic object. It’s interesting to see what happens when, as in the example, you pass a number, then try to double it within the function.</div><div style="font-family: "trebuchet ms", sans-serif;">Figure 1 <b> Using dynamic in the Signature of a Function</b></div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl04" style="font-family: "trebuchet ms", sans-serif;"> </span><br />
<div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl04_"><div class="CodeSnippetTitleBar"><div class="CodeDisplayLanguage"></div></div><div dir="ltr" style="background-color: #dddddd;"><pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl04_code" space="preserve"><span id="ctl00_MTContentSelector1_mainContentContainer_ctl04" style="font-family: "trebuchet ms", sans-serif;">class Program {
static void Main(string[] args) {
// The dynamic variable gets the return
// value of a function call and outputs it.
dynamic x = DoubleIt(2);
Console.WriteLine(x);
// Stop and wait
Console.WriteLine(“Press any key”);
Console.ReadLine();
}
// The function receives and returns a dynamic object
private static dynamic DoubleIt(dynamic p) {
// Attempt to "double" the argument whatever
// that happens to produce
return p + p;
}
}</span></pre></div></div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl04" style="font-family: "trebuchet ms", sans-serif;"></span><br />
<div style="font-family: "trebuchet ms", sans-serif;">If you feed in a value of 2 and try this code, you receive a value of 4. If you feed in 2 as a string, you’ll get 22 instead. Within the function, the + operator is resolved dynamically based on the run time type of the operands. If you change the type to System.Object, you get a compile error, because the + operator isn’t defined on System.Object. The dynamic keyword enables scenarios that weren’t possible without it.</div><h2 style="font-family: "trebuchet ms", sans-serif;">dynamic vs. System.Object</h2><div style="font-family: "trebuchet ms", sans-serif;">Until the .NET Framework 4, having a method return different types according to different conditions was possible only by resorting to a common base class. You’ve probably solved this problem by resorting to System.Object. A function that returns System.Object makes available to the caller an instance that can be cast to nearly anything. So how is using dynamic better than using System.Object?</div><div style="font-family: "trebuchet ms", sans-serif;">In C# 4, the actual type behind the variable that’s declared dynamic is resolved at run time, and the compiler simply assumes that the object in a variable declared dynamic just supports any operations. This means you can really write code that calls a method on the object you expect to be there at run time, as illustrated here:</div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl05" style="font-family: "trebuchet ms", sans-serif;"> </span><br />
<div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl05_"><div class="CodeSnippetTitleBar"><div class="CodeDisplayLanguage"></div></div><div dir="ltr" style="background-color: #dddddd;"><pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl05_code" space="preserve"><span id="ctl00_MTContentSelector1_mainContentContainer_ctl05" style="font-family: "trebuchet ms", sans-serif;">dynamic p = GetSomeReturnValue();
p.DoSomething();</span></pre></div></div><span id="ctl00_MTContentSelector1_mainContentContainer_ctl05" style="font-family: "trebuchet ms", sans-serif;"></span><br />
<div style="font-family: "trebuchet ms", sans-serif;">In C# 4.0, the compiler won’t complain about that code. The analogous code using System.Object won’t compile and requires some hacks on your own—reflection or adventurous casting—in order to work.</div><h2 style="font-family: "trebuchet ms", sans-serif;">var vs. dynamic</h2><div style="font-family: "trebuchet ms", sans-serif;">The keywords var and dynamic are only apparently similar. Var indicates that the type of the variable has to be set to the compile-time type of the initializer.</div><div style="font-family: "trebuchet ms", sans-serif;">But dynamic means that the type of the variable is the dynamic type as available in C# 4.0. In the end, dynamic and var have quite opposite meanings. Var is about reinforcing and improving static typing. It aims to ensure that the type of a variable is inferred by the compiler looking at the exact type being returned by the initializer.</div><div style="font-family: "trebuchet ms", sans-serif;">The keyword dynamic is about avoiding static typing altogether. When used in a variable declaration, dynamic instructs the compiler to stop working out the type of the variable at all. The type has to be intended as the type it happens to have at run time. With var, your code is as statically typed as it would have been had you opted for the classic approach of using explicit types in a variable declaration.</div><div style="font-family: "trebuchet ms", sans-serif;">Another difference between the two keywords is that var can only appear within a local variable declaration. You can’t use var to define a property on a class, nor can you use it to specify the return value or a parameter of a function.</div><div style="font-family: "trebuchet ms", sans-serif;">As a developer, you use the dynamic keyword with variables expected to contain objects of uncertain type such as objects returned from a COM or DOM API; obtained from a dynamic language (IronRuby, for example); from reflection; from objects built dynamically in C# 4.0 using the new expand capabilities.</div><div style="font-family: "trebuchet ms", sans-serif;">The dynamic type doesn’t bypass type checks, though. It only moves them all to run time. If type incompatibilities are discovered at run time, then exceptions are thrown.</div><div style="font-family: "trebuchet ms", sans-serif;"><br />
</div><div style="font-family: "trebuchet ms", sans-serif;">Link of this Article:</div><div style="font-family: "trebuchet ms", sans-serif;"><i>http://msdn.microsoft.com/en-us/magazine/ee336309.aspx</i> </div><div style="font-family: "trebuchet ms", sans-serif;"><i><br /></i></div><div style="font-family: "trebuchet ms", sans-serif;"><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";">My Youtube channel:</div><div class="separator" style="clear: both; font-family: "Times New Roman";"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><br /></div><div class="separator" style="clear: both; font-family: "Times New Roman";"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div><div style="font-family: "trebuchet ms", sans-serif;"></div><hr style="font-family: "trebuchet ms", sans-serif;" /><br /><b style="font-family: "trebuchet ms", sans-serif;"></b>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com0tag:blogger.com,1999:blog-5805048727259686049.post-91092596297067277942010-04-14T18:38:00.003+05:002020-06-26T17:52:47.966+05:00Swap two variables without create any third temp variable int a = 2;<br />
int b = 3;<br />
<br />
a = b + a; // a is 5<br />
b = a - b; // now b is 2<br />
a = a - b; // now a is 3<br />
<br />
Console.Write("a = ");<br />
Console.WriteLine(a);<br />
Console.Write("b = ");<br />
Console.WriteLine(b);<br />
Console.ReadLine();<div><br /></div><div><div class="separator" style="clear: both;"><font face="verdana" size="2">**************************LINKS******************************</font></div><div class="separator" style="clear: both;"><font face="verdana" size="2"><br /></font></div><div class="separator" style="clear: both;"><font face="verdana" size="2">I have created a new better blog:</font></div><div class="separator" style="clear: both;"><a href="https://hammadsiddiquiblog.wordpress.com/">https://hammadsiddiquiblog.wordpress.com/</a></div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">My Youtube channel:</div><div class="separator" style="clear: both;"><a href="https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/">https://www.youtube.com/channel/UCo-MRxKf_MttmSN9WddYdbw/</a></div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;"><span style="font-family: verdana; font-size: small;">**************************LINKS******************************</span></div></div>hammadsiddiquihttp://www.blogger.com/profile/15011281456688017401noreply@blogger.com1