<?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 : C# 3.0</title><link>http://msmvps.com/blogs/chakravarthy/archive/tags/C_2300_+3.0/default.aspx</link><description>Tags: C# 3.0</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><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>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><item><title>Microsoft Test Automation User Group - MTAUG.net</title><link>http://msmvps.com/blogs/chakravarthy/archive/2007/07/19/microsoft-test-automation-user-group-mtaug-net.aspx</link><pubDate>Thu, 19 Jul 2007 10:28:28 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1039228</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=1039228</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1039228</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2007/07/19/microsoft-test-automation-user-group-mtaug-net.aspx#comments</comments><description>&lt;p&gt;A new user group that is taking into shape, specially for the teams that involve software testing. You can get to know more about this user group from &lt;a href="http://mtaug.net"&gt;http://mtaug.net&lt;/a&gt; or get onto &lt;a href="http://groups.msn.com/mtaug"&gt;http://groups.msn.com/mtaug&lt;/a&gt; &lt;/p&gt; &lt;p&gt;This group is going to be functioning in&amp;nbsp;parallel with &amp;quot;&lt;strong&gt;&lt;font color="#004080"&gt;Hyderabad .NET User Group&lt;/font&gt;&lt;/strong&gt;&amp;quot;, &lt;a href="http://muag.net"&gt;http://muag.net&lt;/a&gt; or &lt;a href="http://groups.msn.com/hyde"&gt;&lt;a title="http://groups.msn.com/dotNETUserGroupHyd" href="http://groups.msn.com/dotNETUserGroupHyd"&gt;http://groups.msn.com/dotNETUserGroupHyd&lt;/a&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Tomorrow, 20th July 2007, is going to be the launch of the group. Am going to be there as a speaker for C# 3.0 fundamentals.. are you ?&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://msmvps.com/blogs/chakravarthy/WindowsLiveWriter/MicrosoftTestAutomationUserGroupMTAU.net_EC76/image_1.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="120" alt="image" src="http://msmvps.com/blogs/chakravarthy/WindowsLiveWriter/MicrosoftTestAutomationUserGroupMTAU.net_EC76/image_thumb_1.png" width="240" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1039228" 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/MyEvent/default.aspx">MyEvent</category><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/Hyderabad/default.aspx">Hyderabad</category></item></channel></rss>