<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Chakravarthy's Space : Code</title><link>http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx</link><description>Tags: Code</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>CheckBoxList validation</title><link>http://msmvps.com/blogs/chakravarthy/archive/2009/05/21/checkboxlist-validation.aspx</link><pubDate>Thu, 21 May 2009 05:04:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692892</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1692892</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1692892</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2009/05/21/checkboxlist-validation.aspx#comments</comments><description>&lt;p&gt;Within our current project, we faced a requirement such that there are multiple checkboxes and the user is required to select any one of them (at least one of them). So as there are multiple checkboxes, decided to go with CheckBoxList control. Now the problem is that, we need to show a error message if the user is not selected any one of them. The problem also extends not just there, but the display text should be culture specific.&lt;/p&gt;  &lt;p&gt;So the story started long after I&amp;#39;ve written this post. But editing this entire post due to a simple non supportive feature by IE. I’ll come to that point later in this post, let me first detail the requirement and solution. There is one more solution for this unsupported error. Please read thru the post.&lt;/p&gt;  &lt;p&gt;For all the client side validations, it is widely known that validation controls supported by ASP.NET framework are popularly used. But these controls can’t handle the CheckBoxList. Hence the following solution.&lt;/p&gt;  &lt;p&gt;Step 1: Place your CheckBoxList control in a separate div as shown below. Observe that the text for these controls are populated from database depending upon the user culture&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblItems1&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CheckBoxList &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblOptions&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, Repair&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, Calibration&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, RepairCalibration&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, OnlineService&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CheckBoxList&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Step 2: Use ASP:Lable and get the error message while loading and place in a separate div and hide this div by default as mentioned below. Please note the div ID as &lt;font color="#0000ff"&gt;cblError1&lt;/font&gt; and the style is set to hidden by default&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblError1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt;visibility&lt;/span&gt;: &lt;span style="color:blue;"&gt;hidden&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;lblReq1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, SelectAny&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Step 3: Write a JScript function that reads all the client side rendered elements as &lt;font color="#0000ff"&gt;input&lt;/font&gt; objects and checks whether any of them are checked or not. Code explains more in detail&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;function &lt;/span&gt;CheckListValidation(cblItm, errDiv)
{
&lt;span style="color:green;"&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;tDiv = document.getElementById(cblItm);
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;chkitems = tDiv.childNodes[1];
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;chkitm = chkitems.getElementsByTagName(&lt;span style="color:#a31515;"&gt;&amp;quot;input&amp;quot;&lt;/span&gt;);
    &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;i = 0; i &amp;lt; chkitm.length; i++) 
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(chkitm.checked) 
        {                    
                &lt;span style="color:blue;"&gt;return true&lt;/span&gt;;
        }
    }
    document.getElementById(errDiv).style.visibility = &lt;span style="color:#a31515;"&gt;&amp;#39;visible&amp;#39;&lt;/span&gt;;
    &lt;span style="color:blue;"&gt;return false&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Step 4: Now it is the turn of invoking this function from the button click. Every button is having a method called as “OnClientClick” along with Click. Invoke this function from that method as mentioned below&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnAddMore&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Add More&amp;quot; 
&lt;/span&gt;&lt;span style="color:red;"&gt;OnClientClick&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;return CheckListValidation(&amp;#39;cbOptions&amp;#39;,&amp;#39;cblError1&amp;#39;);&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;OnClick&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnAddMore_Click&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Step 5: All setup and the code is running fine. But there is a problem with this code while running in IE. IE 6 and above doesn’t support the getElementsByTag &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;vTe = document.getElementsByTagName(..);&lt;/pre&gt;
There is a long story for this. Let me post one more post for the better mechanism of CheckBoxList Validation. Until then, what are your comments?? 

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1692892" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/.NET/default.aspx">.NET</category></item><item><title>VS 2008 and .NET 3.5 Training Kit</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/12/17/vs_2D00_2008_2D00_and_2D00_net_2D00_35_2D00_training_2D00_kit.aspx</link><pubDate>Mon, 17 Dec 2007 09:40:07 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1401422</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1401422</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1401422</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/12/17/vs_2D00_2008_2D00_and_2D00_net_2D00_35_2D00_training_2D00_kit.aspx#comments</comments><description>&lt;p&gt;The Visual Studio 2008 and .NET Framework 3.5 Training Kit includes presentations, hands-on labs, and demos. &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8BDAA836-0BBA-4393-94DB-6C3C4A0C98A1&amp;amp;displaylang=en"&gt;This content&lt;/a&gt; is designed to help you learn how to utilize the Visual Studio 2008 features and a variety of framework technologies including: LINQ, C# 3.0, Visual Basic 9, WCF, WF, WPF, ASP.NET AJAX, VSTO, CardSpace, SilverLight, Mobile and Application Lifecycle Management.&lt;/p&gt; &lt;p&gt;I&amp;#39;ve downloaded this, if any one require this, you can drop me a mail or can collect from me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1401422" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Microsoft+Promotions/default.aspx">Microsoft Promotions</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tutorials/default.aspx">Tutorials</category></item><item><title>ASP.NET 3.5 Extensions Preview</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/12/10/asp-net-3-5-extensions-preview.aspx</link><pubDate>Mon, 10 Dec 2007 15:15:08 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1390347</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1390347</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1390347</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/12/10/asp-net-3-5-extensions-preview.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://quickstarts.asp.net/3-5-extensions/default.aspx"&gt;ASP.NET 3.5 Extensions&lt;/a&gt; Preview provides a glimpse of new, powerful functionality being added to ASP.NET 3.5 and ADO.NET next year. This release delivers features that enable high-productivity data scenarios and creates the best server for rich clients. The release includes an &lt;a href="http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx"&gt;ASP.NET model-view-controller&lt;/a&gt; (MVC) framework, &lt;a href="http://quickstarts.asp.net/3-5-extensions/dyndata/default.aspx"&gt;ASP.NET Dynamic Data&lt;/a&gt;, &lt;a href="http://quickstarts.asp.net/3-5-extensions/silverlight/default.aspx"&gt;Silverlight controls for ASP.NET&lt;/a&gt;, &lt;a href="http://quickstarts.asp.net/3-5-extensions/adonetdataservice/default.aspx"&gt;ADO.NET Data Services&lt;/a&gt;, an Entity Framework runtime, new features for &lt;a href="http://quickstarts.asp.net/3-5-extensions/ajax/default.aspx"&gt;ASP.NET AJAX&lt;/a&gt; and a wide variety of &lt;a href="http://quickstarts.asp.net/3-5-extensions/reference/default.aspx"&gt;API References&lt;/a&gt; as hosted at ASP.NET Official site.&lt;/p&gt; &lt;p&gt;You can &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A9C6BC06-B894-4B11-8300-35BD2F8FC908&amp;amp;displaylang=en"&gt;download the ASP.NET 3.5 Preview&lt;/a&gt;, which contain all the Siliverlight controls, ADO.NET Data Services and many more. There is a &lt;a href="http://forums.asp.net/default.aspx?GroupID=7"&gt;forum&lt;/a&gt; specially dedicated to &lt;a href="http://forums.asp.net/default.aspx?GroupID=7"&gt;ASP.NET 3.5 Preview&lt;/a&gt; at &lt;a href="http://forums.asp.net"&gt;ASP.NET Forums&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1390347" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Community/default.aspx">Community</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/UserGroup/default.aspx">UserGroup</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/v3.5/default.aspx">v3.5</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Calling .NET Component from a classic ASP page</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/12/06/calling_2D00_net_2D00_component_2D00_from_2D00_a_2D00_classic_2D00_asp_2D00_page.aspx</link><pubDate>Thu, 06 Dec 2007 11:24:07 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1382520</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1382520</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1382520</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/12/06/calling_2D00_net_2D00_component_2D00_from_2D00_a_2D00_classic_2D00_asp_2D00_page.aspx#comments</comments><description>&lt;p&gt;After a long time, today, got a requirement from ASP page. Our current client has a major application written in classic ASP 2.0, and we have given him an extension functionality written in .NET with VB as programming language.&lt;/p&gt; &lt;p&gt;Now, we have 2 different applications running at the same box with 2 different technologies, ie., an ASP application and an ASP.NET application. For both of the applications, there is a common functionality talking to the database via a webservice written in Java. The current situation demand a common library that will be reused at both ASP.NET pages as well as ASP pages. Apart of the requirement, the one point that led me to post here is &amp;quot;How to call a .NET Assembly in a Classic page&amp;quot;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating .NET Assembly&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span&gt;Imports&lt;/span&gt; System
&lt;span&gt;Imports&lt;/span&gt; System.Runtime.InteropServices
&lt;span&gt;Public&lt;/span&gt; &lt;span&gt;Class&lt;/span&gt; MyLibClass
    &lt;span&gt;Public&lt;/span&gt; &lt;span&gt;Function&lt;/span&gt; MyLibFunction() &lt;span&gt;As&lt;/span&gt; &lt;span&gt;String
&lt;/span&gt;        &lt;span&gt;Return&lt;/span&gt; &lt;span&gt;&amp;quot; Invoked the method from COM successfully ..&amp;quot;
&lt;/span&gt;    &lt;span&gt;End&lt;/span&gt; &lt;span&gt;Function
End&lt;/span&gt; &lt;span&gt;Class&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;With the above code, you can generate a .NET DLL after compiling with either Visual Basic Command Line Utility, VBC.EXE or from the Visual Studio Environment. While compiling this code, give extra attention at the assembly attribute to make the DLL Visible to COM as mentioned below. &lt;/p&gt;&lt;pre class="code"&gt;&amp;lt;Assembly: ComVisible(&lt;span&gt;True&lt;/span&gt;)&amp;gt; &lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;If you are using the Visual Studio Environment, go to the Project Properties, at the &lt;strong&gt;Compile&lt;/strong&gt; section don&amp;#39;t forget to check the &amp;quot;&lt;strong&gt;Register COM interop&lt;/strong&gt;&amp;quot; check box. This check box will be by default unchecked, indicating that the DLL will not be exposed to COM.&lt;/p&gt;
&lt;p&gt;Now the assembly is ready to reuse. But before we start the actual implementation, if you want the Assembly should be register with the GAC, you have to take the assistance from &lt;strong&gt;StrongNameKey&lt;/strong&gt; file. You can create a Strongname Key file with the command utility SN.EXE or from the Visual Studio as well. The command to create the Strongname Key file is as mentioned below&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; sn -k strongnamekeyfile.snk&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Once you are done with the strong name key file generation, you can attach the key file either with the /keyfile:strongnamekeyfile.snk option or with the assembly attribute as &amp;lt;Assembly: AssemblyKeyFile(&lt;span&gt;&amp;quot;strongnamekeyfile.snk&amp;quot;&lt;/span&gt;)&amp;gt; &lt;/p&gt;
&lt;p&gt;Now it is the final time to compile your code and do the calling stuff from ASP page. Once you compile the code from Visual Studio, you will have 3 files, .PDB / .TLB / .DLL. The .DLL is the actual file. You have to do 2 things to share this DLL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Register as COM as well as with GAC&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now that the DLL is ready, we will take the assistance of REGASM command line utility to register as public assembly.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; regasm /codebase /tlb:a.tlb OurAssemblyFile.dll&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;With this command, the DLL will be registering at the registry. Please don&amp;#39;t forget to use the&lt;strong&gt;&lt;font color="#0f1b84"&gt; /codebase&lt;/font&gt;&lt;/strong&gt; option. To register the same with GAC use the following command&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; gacutil /if OutAssemblyFile.dll&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This command will register with the GAC and is available as reference within the .NET Framework. With the first command, the object is ready to invoke from ASP code. You can use the COM component with &lt;font color="#000080"&gt;&lt;strong&gt;Server.CreateObject(&amp;quot;OurAssemblyFile.ClassName&amp;quot;)&lt;/strong&gt;&lt;/font&gt; command from ASP page. The actual implementation at any ASP page will look like as mentioned below&lt;/p&gt;&lt;pre class="code"&gt; &lt;span&gt;dim&lt;/span&gt; objCom 
 &lt;span&gt;set&lt;/span&gt; objCom = Server.CreateObject(&lt;span&gt;&amp;quot;libraryNameSpace.libraryClass&amp;quot;&lt;/span&gt;)
 objCom.DoSomeWork() &lt;span&gt;&amp;#39; this method doesn&amp;#39;t return any value&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Finally, if this page throw any kind of error as &lt;strong&gt;&lt;font color="#000080"&gt;Unindentified Class name&lt;/font&gt;&lt;/strong&gt;, then the only solution &lt;strong&gt;&lt;u&gt;is to reset the IIS&lt;/u&gt;&lt;/strong&gt;.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1382520" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/COM/default.aspx">COM</category></item><item><title>C# 3.0 - What's New : {Properties}-Part2</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/10/12/c-3-0-what-s-new-properties-part2.aspx</link><pubDate>Fri, 12 Oct 2007 10:07:56 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1244258</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1244258</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1244258</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/10/12/c-3-0-what-s-new-properties-part2.aspx#comments</comments><description>&lt;p&gt;Property of the class can be considered as the mechanism of accessing the private variables of the class. In other words, properties act as wrappers to the private variables. Though, the new feature related to this is not so great from the point of technology, but highly meaningful from the developer point of view. In a large class code, having many fields and exposed as Properties, it is really difficult to remember the private fields association with the respective definition of properties. The new feature of Properties in C# 3.0 language specification says that the developer doesn&amp;#39;t require to define the private variables that are associated with the respective properties. During the good olden days, we are used to the following coding mechanism to declare the property via a private variable.&lt;/p&gt;&lt;pre class="code"&gt;        &lt;span&gt;// The private Variable declaration
&lt;/span&gt;        &lt;span&gt;string&lt;/span&gt; strEmpName;

        &lt;span&gt;// Property Declaration
&lt;/span&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; EmployeeName
        {
            &lt;span&gt;get&lt;/span&gt; {
                &lt;span&gt;// Returning the value from the private variable
&lt;/span&gt;                &lt;span&gt;return&lt;/span&gt; strEmpName;
                }
            &lt;span&gt;set&lt;/span&gt; {
                &lt;span&gt;// Assigning the value to private Variable
&lt;/span&gt;                strEmpName = &lt;span&gt;value&lt;/span&gt;; 
                }
        }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;But hence forth, by using the C# 3.0 version, we doesn&amp;#39;t require to define as above but just as simple as mentioned below&lt;/p&gt;&lt;pre class="code"&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; EmployeeName { &lt;span&gt;get&lt;/span&gt;; &lt;span&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;How simple is this, by this method we doesn&amp;#39;t require to remember which is property and which is a private variable. But bottom line remains the same as of the old tradition, the only thing that every one has to remember is that, there is no need to declare a private variable and association of the same with the exposed property. Beneath the code, the compiler creates a private variable for each property that you define as such. To justify, use any reflector to understand the emitted IL code and the Assembly signature. You will surprise to note that a separate private variable is associated by the compiler. &lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:68598688-ddf2-4ccc-b034-f69a8b021ad4" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/C#%20v3.0" rel="tag"&gt;C# v3.0&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1244258" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/C_2300_+3.0/default.aspx">C# 3.0</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Hyderabad/default.aspx">Hyderabad</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/InteQ/default.aspx">InteQ</category></item><item><title>The importance of 'Return' keyword at JavaScript</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/09/15/the-importance-of-return-keyword-at-javascript.aspx</link><pubDate>Sat, 15 Sep 2007 12:26:53 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1198949</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1198949</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1198949</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/09/15/the-importance-of-return-keyword-at-javascript.aspx#comments</comments><description>&lt;p&gt;Recently, while coding for a Text Field value padded with left zeros, realised the importance of the RETURN key word for the FUNCTION written in JavaScript. Before i mention the actual importance, let me describe you the situation.&lt;/p&gt; &lt;p&gt;Scenario: A Text box need to be padded with zeros and should have the length of 7 digits, even the data entered is less than 7.&lt;/p&gt; &lt;p&gt;Ex: When the key board input being 88, the text box should show &lt;strong&gt;00000&lt;/strong&gt;88. Note the ZEROs padded on left.&lt;/p&gt; &lt;p&gt;So, started with a JavaScript function as mentioned below&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span&gt;function&lt;/span&gt; PadZeros(x)
    {
        &lt;span&gt;var&lt;/span&gt; v = x.value;
        &lt;span&gt;while&lt;/span&gt;(v.length&amp;lt;7)
        {
            v = &lt;span&gt;&amp;#39;0&amp;#39;&lt;/span&gt; + v;
        }
        &lt;span&gt;var&lt;/span&gt; ss = document.getElementById(x.id);
        ss.value = v;
    }&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;After this, the text box is padding with ZEROs and the code is perfectly running. To allow this to code execute for any given text box, all you have to do is, add the ATTRIBUTE to that text box. And while adding keep one thing in mind that, we would be calling this function on BLUR, ie., LOST FOCUS of the text box. The code is as mentioned below.&lt;/p&gt;&lt;pre class="code"&gt;            &lt;span&gt;this&lt;/span&gt;.txtPCode.Attributes.Add(&lt;span&gt;&amp;quot;onblur&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;PadZeros(this);&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Please note the &amp;#39;this&amp;#39; keyword. The usage of &amp;#39;this&amp;#39; keyword has many possibilities. Let me see that, one day will post where the &amp;#39;this&amp;#39; keyword is used and their context. And also note that, neither the function is returning any value nor the text box is added with the code that handles the output of the function. Will come to that in short.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Every thing is working perfectly well and going on smooth. But suddenly, i realised that the text box is just padding ZEROs when there is no Input. I see all ZEROs in the text box as &lt;strong&gt;0000000&lt;/strong&gt;. Then came the real trick to the function.&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span&gt;function&lt;/span&gt; PadZeros(x)
    {
        &lt;span&gt;var&lt;/span&gt; v = x.value;
        &lt;span&gt;if&lt;/span&gt;(v.length == 0)
        {
            &lt;span&gt;var&lt;/span&gt; vTe = document.getElementById(x.id);
            vTe.focus();
            alert(&lt;span&gt;&amp;#39;Please enter Provider Code .. &amp;#39;&lt;/span&gt;);
        }
        &lt;span&gt;while&lt;/span&gt;(v.length&amp;lt;7)
        {
            v = &lt;span&gt;&amp;#39;0&amp;#39;&lt;/span&gt; + v;
        }
        &lt;span&gt;var&lt;/span&gt; ss = document.getElementById(x.id);
        ss.value = v;
    }&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;What do you see here is the mechanism to set the focus back to the text box. Great... but that even is not solving my purpose of leaving the text box blank when there is no input. This function is still adding ZEROs to no input and showing all ZEROs. Then came the purpose of the &lt;strong&gt;&lt;font color="#0080ff"&gt;&amp;#39;return&amp;#39;&lt;/font&gt;&lt;/strong&gt; keyword. The entire requirement is simply solved by this keyword. All i&amp;#39;ve done is.. changed the code as mentioned below.&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span&gt;function&lt;/span&gt; PadZeros(x)
    {
        &lt;span&gt;var&lt;/span&gt; v = x.value;
        &lt;span&gt;if&lt;/span&gt;(v.length == 0)
        {
            &lt;span&gt;var&lt;/span&gt; vTe = document.getElementById(x.id);
            vTe.focus();
            alert(&lt;span&gt;&amp;#39;Please enter Provider Code .. &amp;#39;&lt;/span&gt;);
            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;;
        }
        &lt;span&gt;while&lt;/span&gt;(v.length&amp;lt;7)
        {
            v = &lt;span&gt;&amp;#39;0&amp;#39;&lt;/span&gt; + v;
        }
        &lt;span&gt;var&lt;/span&gt; ss = document.getElementById(x.id);
        ss.value = v;
        &lt;span&gt;return&lt;/span&gt; &lt;span&gt;true&lt;/span&gt;;
    }&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;At the code behind added &amp;#39;return&amp;#39; as shown here &lt;/p&gt;&lt;pre class="code"&gt;            &lt;span&gt;this&lt;/span&gt;.txtPCode.Attributes.Add(&lt;span&gt;&amp;quot;onblur&amp;quot;&lt;/span&gt;, &lt;span&gt;&amp;quot;return PadZeros(this);&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;That&amp;#39;s all.. hoollaa... What do you say ?&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a8c92c9f-3426-4b59-949b-0a4912605601" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/JavaScript" rel="tag"&gt;JavaScript&lt;/a&gt;, &lt;a href="http://technorati.com/tags/PadZeros" rel="tag"&gt;PadZeros&lt;/a&gt;, &lt;a href="http://technorati.com/tags/return" rel="tag"&gt;return&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1198949" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/First/default.aspx">First</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Hyderabad/default.aspx">Hyderabad</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/InteQ/default.aspx">InteQ</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/JavaScript/default.aspx">JavaScript</category></item><item><title>C# 3.0 - What's New : {Implicit}-Part1</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/08/24/c-3-0-what-s-new-implicit-part1.aspx</link><pubDate>Fri, 24 Aug 2007 05:33:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1134530</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1134530</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1134530</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/08/24/c-3-0-what-s-new-implicit-part1.aspx#comments</comments><description>&lt;p&gt;Recent development in my technical life is that, started working out with Orcas Beta 2. So, thought to blog about the latest happenings with C# language. The idea emerged to start a series of posts related to C# new features. This is the first of ever such kind of blogging specific to a topic. 
&lt;p&gt;C# 3.0 has many-a-new features. To start with, let me take a concept of &lt;b&gt;Implicitly Typed Variables&lt;/b&gt;. 
&lt;p&gt;&lt;b&gt;Implicitly Typed Variables&lt;/b&gt; 
&lt;p&gt;In the good old days, the developer has to worry about the type of the variable. Say for instance, whether to use long or double for a counter. Here&amp;nbsp;all that we observe&amp;nbsp;is that the language that is&amp;nbsp;built upon is the type specific.&amp;nbsp;Hence forth the developer is not required to define the type of the variable at the time of declaration, but it is the task of the compiler to decide what type of the object the variable is. All that the developer has to do is that, use the &lt;b&gt;var&lt;/b&gt; keyword while declaring the variable, similar to that of JScript or Visual Basic style. Hey!!! Stop!!!!! don&amp;#39;t get confuse with the type of &lt;strong&gt;VAR&lt;/strong&gt; variables declared at&amp;nbsp;JScript or Visual basic.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s first discuss the difference between VAR variables at JScript and VAR variables of C#&lt;/p&gt;
&lt;table class="" cellspacing="0" cellpadding="2"&gt;

&lt;tr&gt;
&lt;td class="" align="middle"&gt;&lt;font size="2"&gt;VAR JScript&lt;/font&gt;&lt;/td&gt;
&lt;td class="" align="middle"&gt;&lt;font size="2"&gt;VAR C#&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;This is of no type&lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;The type of the variable is defined by the value declared and decided at the compile time&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Technically have no type. Can consider of limited types, namely, string literal, numeric, boolean &lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;Type agnostic, have specific predefined formats&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Type conversion is coercion&lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Type casting is simple and handled by CLR&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;No mechanism for parsing&lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;explicit functions for parsing to specific type&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;Now, let us see the difference between the language specific VAR of VisualBasic 6.0&amp;nbsp;and C# 3.0&lt;/p&gt;
&lt;table class="" cellspacing="0" cellpadding="2"&gt;

&lt;tr&gt;
&lt;td class="" align="middle"&gt;&lt;font size="2"&gt;VAR in VB (but not .NET)&lt;/font&gt;&lt;/td&gt;
&lt;td class="" align="middle"&gt;&lt;font size="2"&gt;VAR in C# 3.0&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;By definition, these are Variant &lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Type of the variable is defined at the compile time&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Could be any allowed type from with in the known types of the language&lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Type is decided by the value associated with the variable&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Largest among all the known&amp;nbsp;data tydpes&lt;/font&gt;&lt;/td&gt;
&lt;td class=""&gt;&lt;font size="2"&gt;Size depends on the type of the&amp;nbsp;value initialised&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;p&gt;To summarize, the variables declared in C# 3.0 are type specific, &lt;strong&gt;thou&lt;/strong&gt; used the key word &lt;strong&gt;VAR&lt;/strong&gt;, during the declaration. Thus, we can conclude that the compiler is the responsible point to decide the type of the variable. Hence we can say with&amp;nbsp;comfort that, the variables from C# 3.0 are &lt;strong&gt;Implicitly Typed&lt;/strong&gt; variables. &lt;/p&gt;
&lt;p&gt;Some examples as mentioned below.&lt;/p&gt;&lt;pre class="code"&gt;            &lt;span&gt;var&lt;/span&gt; vIntVal = 10; &lt;span&gt;// This will be the System.Int32 type
&lt;/span&gt;            &lt;span&gt;var&lt;/span&gt; vLongVal = 10000000000; &lt;span&gt;// This will be the System.Int64 type
&lt;/span&gt;            &lt;span&gt;var&lt;/span&gt; vDoubleVal = 10.0; &lt;span&gt;// This will be the System.Double type
&lt;/span&gt;            &lt;span&gt;var&lt;/span&gt; vFloatVal = 10.0f; &lt;span&gt;// This will be the System.Single type
&lt;/span&gt;            &lt;span&gt;float&lt;/span&gt; vFlVal = 10.0f; &lt;span&gt;// Thou defined using float key word, but inherits from Struct System.Single 
&lt;/span&gt;            &lt;span&gt;var&lt;/span&gt; vStrVal = &lt;span&gt;&amp;quot;String Value &amp;quot;&lt;/span&gt;;  &lt;span&gt;// This will be the System.String type
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;So, from the above declarations, it is pretty clear that the variable is defined by the value associated during the declaration. The type is not just limited to the kind of data types as explained above, but you can extend this to any type of the variable that you use while writing code for iterations, similar such as &lt;strong&gt;&lt;font color="#0000ff"&gt;foreach&lt;/font&gt;&lt;/strong&gt;. Below is the example for other known types.&lt;/p&gt;&lt;pre class="code"&gt;            &lt;span&gt;foreach&lt;/span&gt; (&lt;span&gt;var&lt;/span&gt; vTable &lt;span&gt;in&lt;/span&gt; ds.Tables) &lt;span&gt;// Implicitly declared a variable of Data Table Type
&lt;/span&gt;            {
                &lt;span&gt;foreach&lt;/span&gt; (&lt;span&gt;var&lt;/span&gt; vRow &lt;span&gt;in&lt;/span&gt; ((&lt;span&gt;DataTable&lt;/span&gt;) vTable).Rows) &lt;span&gt;// Implicit declaration of DataRow variable
&lt;/span&gt;                {

                }
            }
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;By using such, one can extend any extent. The limit is the imagination of the developer. What do you say?&lt;/p&gt;
&lt;p&gt;Source: &lt;/p&gt;
&lt;p&gt;1) &lt;a title="http://cobdev.cob.isu.edu/psb/jscript/306.htm" href="http://cobdev.cob.isu.edu/psb/jscript/306.htm"&gt;http://cobdev.cob.isu.edu/psb/jscript/306.htm&lt;/a&gt;&amp;nbsp;for JScript&lt;br /&gt;2) &lt;a title="http://www.1sayfa.com/1024/diger/vb/ch07.htm" href="http://www.1sayfa.com/1024/diger/vb/ch07.htm"&gt;http://www.1sayfa.com/1024/diger/vb/ch07.htm&lt;/a&gt;&amp;nbsp;for Visual Basic 6.0 Datatypes&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:80c6bbbe-a3e3-4b04-813c-476e8089f26c" style="PADDING-RIGHT:0px;DISPLAY:inline;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:0px;PADDING-TOP:0px;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/CSharp" rel="tag"&gt;CSharp&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/3.0" rel="tag"&gt;3.0&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Code" rel="tag"&gt;Code&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Tips" rel="tag"&gt;Tips&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Implicit" rel="tag"&gt;Implicit&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1134530" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/C_2300_+3.0/default.aspx">C# 3.0</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Definition/default.aspx">Definition</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/First/default.aspx">First</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category></item><item><title>Runtime Polymorphism</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/08/20/runtime-polymorphism.aspx</link><pubDate>Mon, 20 Aug 2007 11:00:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1125966</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1125966</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1125966</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/08/20/runtime-polymorphism.aspx#comments</comments><description>&lt;p style="margin-bottom:0.19in;"&gt;&lt;span style="color:#111111;"&gt;One of the frequently seen situations from a technical standpoint in a large scale of Business Layer objects is, invoking methods from different objects when they contain same method name. Today, am going to make it simple to give an example for Runtime Polymorphism. Leave your comments if am mistaken&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;At this stage, I don’t think to mention about &amp;quot;Polymorphism&amp;quot;, as hope that you are aware of how polymorphic behavior can be fused using C#. If you want a start up, in simple words, implementation of one Method with many definitions, as mentioned below.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; &lt;span style="color:#008080;"&gt;Employee&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; Invoked for the Regular salaried employes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;param name=&amp;quot;intEmpId&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;Employee ID&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;param name=&amp;quot;intAbscentDays&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;Number of days&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;long&lt;/span&gt; CalculateSal(&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; intEmpId, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; intAbscentDays)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; (GetEmpSal(intEmpId) * (GetWorkingDays(&lt;span style="color:#008080;"&gt;DateTime&lt;/span&gt;.Now.Month) - intAbscentDays));&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; Invoked for the employees, who work as Daily wage&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;param name=&amp;quot;lSalPerDay&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;Salary per day&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;param name=&amp;quot;intDays&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;For number of days&lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#808080;"&gt;///&lt;/span&gt;&lt;span style="color:#008000;"&gt; &lt;/span&gt;&lt;span style="color:#808080;"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;long&lt;/span&gt; CalculateSal(&lt;span style="color:#0000ff;"&gt;long&lt;/span&gt; lSalPerDay, &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; intDays)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; lSalPerDay * intDays;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;A simple way of invoking is as mentioned below.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#008080;"&gt;Employee&lt;/span&gt; eTe = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#008080;"&gt;Employee&lt;/span&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;long&lt;/span&gt; lSal = eTe.CalculateSal(124, 2);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="color:#0000ff;"&gt;long&lt;/span&gt; lSal = eTe.CalculateSal(678.35, 18);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;So, by now, you are clear how to write polymorphic method and as well as how to use. Let’s jump to how you can make the Runtime Polymorphism.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;To continue the discussion, first we need to know that there are 2 basic&amp;nbsp;types of polymorphism. They are, Overloading, referred as Compile time polymorphism, and Overriding also called as Run-Time polymorphism. What you have seen above is the first kind of polymorphism. The second type is referred as late binding. In other words, &lt;strong&gt;&lt;font face="gar" color="#000080"&gt;the selection of the method for execution at runtime depends on the reference of the actual&amp;nbsp;object that is triggering the invoking of the method&lt;/font&gt;&lt;/strong&gt;. Now let&amp;#39;s explore that with some example.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;Let us take a small class, as mentioned below&amp;nbsp;with few properties. This class acts as a base class for us.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom:0.19in;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; &lt;span&gt;EmpNames&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; FirstName { &lt;span&gt;get&lt;/span&gt;; &lt;span&gt;set&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; MiddleName { &lt;span&gt;get&lt;/span&gt;; &lt;span&gt;set&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;public&lt;/span&gt; &lt;span&gt;string&lt;/span&gt; LastName { &lt;span&gt;get&lt;/span&gt;; &lt;span&gt;set&lt;/span&gt;; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;We will now inherit this into the following classes. Observe that the both classes doesn&amp;#39;t have any direct relation with each other and can be instantiated as is.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; This class calculate the wages for given number of days
&lt;/span&gt;    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; &lt;span&gt;Wages&lt;/span&gt; : &lt;span&gt;EmpNames&lt;/span&gt; 
    {
        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; This will calculate the wages for the employees
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;param name=&amp;quot;Params&amp;quot;&amp;gt;&lt;/span&gt;&lt;span&gt;Wage per Day, Number of Working days in a month&lt;/span&gt;&lt;span&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span&gt; WagePerDay * WorkingDays &lt;/span&gt;&lt;span&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;double&lt;/span&gt; CalculateSalary(&lt;span&gt;ArrayList&lt;/span&gt; Params)
        {
            &lt;span&gt;return&lt;/span&gt; &lt;span&gt;double&lt;/span&gt;.Parse(Params[0].ToString()) * &lt;span&gt;int&lt;/span&gt;.Parse(Params[1].ToString());
        }
    }


    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; This class will calculate the salary
&lt;/span&gt;    &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;    &lt;span&gt;public&lt;/span&gt; &lt;span&gt;class&lt;/span&gt; &lt;span&gt;Salried&lt;/span&gt; : &lt;span&gt;EmpNames
&lt;/span&gt;    {
        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; This will calculate the salary for the employees
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;param name=&amp;quot;Params&amp;quot;&amp;gt;&lt;/span&gt;&lt;span&gt;Working days Per Month, Leaves, Salary Per Month&lt;/span&gt;&lt;span&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;        &lt;span&gt;///&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span&gt; Full Salary in case no value for Leaves. Other case, (SalaryPerMonth/WorkingDays) * (WorkingDays - Leaves) &lt;/span&gt;&lt;span&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;        &lt;span&gt;public&lt;/span&gt; &lt;span&gt;double&lt;/span&gt; CalculateSalary(&lt;span&gt;ArrayList&lt;/span&gt; Params)
        {
            &lt;span&gt;double&lt;/span&gt; dSal=&lt;span&gt;double&lt;/span&gt;.Parse(Params[2].ToString());
            &lt;span&gt;int&lt;/span&gt; intLeaves = &lt;span&gt;int&lt;/span&gt;.Parse(Params[1].ToString());
            &lt;span&gt;if&lt;/span&gt; (!intLeaves.Equals(0))
            {
                &lt;span&gt;int&lt;/span&gt; intWrkDays = &lt;span&gt;int&lt;/span&gt;.Parse(Params[0].ToString());
                dSal = (dSal / intWrkDays) * (intWrkDays - intLeaves);
            }
            &lt;span&gt;return&lt;/span&gt; dSal;
        }
    }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;Now that we have these two classes, We can write our code to instantiate them as individual. But the point of this post is to describe the &amp;quot;RunTime Polymorphism&amp;quot;. Before we go further, note that, each class has the method &amp;quot;&lt;strong&gt;&lt;font color="#0000ff"&gt;CalculateSalary&lt;/font&gt;&lt;/strong&gt;&amp;quot; and as they are not directly related, you can instantiate them with out any hassle.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;            &lt;span&gt;EmpNames&lt;/span&gt; empObj;&lt;/pre&gt;&lt;pre class="code"&gt;            &lt;span&gt;ArrayList&lt;/span&gt; alValues = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;ArrayList&lt;/span&gt;();
            alValues.Add(30); &lt;span&gt;//Just add all the fields as this&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;            &lt;span&gt;bool&lt;/span&gt; bSalaried = &lt;span&gt;true&lt;/span&gt;; &lt;span&gt;//am using this variable for validation of emp&lt;/span&gt;

            &lt;span&gt;if&lt;/span&gt; (bSalaried) &lt;span&gt;//Validating whether Salaried or Wages &lt;/span&gt;
                empObj = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;Salried&lt;/span&gt;();
            &lt;span&gt;else
&lt;/span&gt;                empObj = &lt;span&gt;new&lt;/span&gt; &lt;span&gt;Wages&lt;/span&gt;();&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;After executing the above lines of code, you are sure about the type of the variable empObj. This is Runtime initiating the object. But this is not the purpose of our current topic.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;            &lt;span&gt;double&lt;/span&gt; dVal;

            &lt;span&gt;//The below line will throw compile time error
&lt;/span&gt;            &lt;span&gt;//dVal = empObj.CalculateSalary(alValues);
&lt;/span&gt;            dVal = ((&lt;span&gt;Wages&lt;/span&gt;) empObj).CalculateSalary(alValues);
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new, monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Courier New"&gt;What do you see from the last line of the above code? Did you find that the method invoked is from a class type. Now, think that, what if the class is being instantiated as Salaried and the last line is being invoked?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;This is called as RunTime Polymorphism.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:31e4289c-ec2b-438f-9f1d-d9e421aa3246" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Runtime%20Polymorphism" rel="tag"&gt;Runtime Polymorphism&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/CSharp" rel="tag"&gt;CSharp&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Tips" rel="tag"&gt;Tips&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p style="margin-bottom:0.19in;"&gt;&lt;br /&gt;-----------------------&lt;br /&gt;&amp;nbsp;Declaimer: What ever you read here is out of my own experience. No one shall be made responsible for the contents and issues that are mentioned here. If you have something to share in person on this post, pl drop me a mail at dskcheck@gmail.com with the title in the subject.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1125966" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/C_2300_+3.0/default.aspx">C# 3.0</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/First/default.aspx">First</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/RunTime+Polymorphsim/default.aspx">RunTime Polymorphsim</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category></item></channel></rss>