<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.NET Tips and Tricks &#187; Inheritance</title>
	<atom:link href="http://kossovsky.net/index.php/tag/inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://kossovsky.net</link>
	<description>C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks</description>
	<lastBuildDate>Sat, 25 Dec 2010 08:32:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>C# Protected Internal</title>
		<link>http://kossovsky.net/index.php/2009/06/cshar-protected-internal/</link>
		<comments>http://kossovsky.net/index.php/2009/06/cshar-protected-internal/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 21:15:25 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[a3]]></category>
		<category><![CDATA[access modifier]]></category>
		<category><![CDATA[access modifiers]]></category>
		<category><![CDATA[c developers]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[class a2]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[internal]]></category>
		<category><![CDATA[limited]]></category>
		<category><![CDATA[members]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[protected]]></category>
		<category><![CDATA[protected internal]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[public access]]></category>
		<category><![CDATA[public string]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=242</guid>
		<description><![CDATA[I&#8217;ve noticed that most of the c# developers i&#8217;am talking to, know exactly what &#8220;public&#8221;, &#8220;private&#8221;, &#8220;protected&#8221; and &#8220;internal&#8221; access modifiers mean and how to use them, but when it comes to &#8220;protected internal&#8221; they start guessing the answer and it&#8217;s never the right one. Well, let&#8217;s make some order in that. protected A protected [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.8" /></div><div>Rating: 4.8/<strong>5</strong> (15 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve noticed that most of the c# developers i&#8217;am talking to, know exactly what &#8220;public&#8221;, &#8220;private&#8221;, &#8220;protected&#8221; and &#8220;internal&#8221; access modifiers mean and how to use them, but when it comes to &#8220;protected internal&#8221; they start guessing the answer and it&#8217;s never the right one.</p>
<p><span id="more-242"></span></p>
<p>Well, let&#8217;s make some order in that.</p>
<p><strong>protected</strong><br />
A protected member is accessible <span style="text-decoration: underline;">within its class and by derived classes</span>.</p>
<p><strong>internal</strong><br />
Internal types or members are accessible <span style="text-decoration: underline;">only within files in the same assembly</span>.</p>
<p><strong>protected internal</strong><br />
Access is limited to the <span style="text-decoration: underline;">current assembly or types derived from the containing class</span>.<br />
* protected internal is the <span style="text-decoration: underline;">only access modifiers combination</span> allowed for a member or a type.</p>
<p>So, as we can see &#8220;protected internal&#8221; can be used in the same assembly or types derived from the containing class in any assembly.</p>
<p>It means that we can access a &#8220;protected internal&#8221; method by accessing any instance of it&#8217;s class in the same assembly, in any class in different assembly which derives from the class, but we won&#8217;t be able to access the method by accessing an instance of it&#8217;s class in different assembly.</p>
<pre class="c-sharp" name="code">// Assemby : A
namespace AssemblyA
{
    public class A
    {
        protected internal string SomeProtectedInternalMethod() {
            return "SomeValue";
        }
    }

    public class A2 : A
    {
        public string SomeMethod() {
            // We can access the method because
            // it's protected and inherited by A2
            return SomeProtectedInternalMethod();
        }
    }

    class A3 : A
    {
        public string SomeMethod()
        {
            A AI = new A();
            // We can access the method through an instance
            // of the class because it's internal
            return AI.SomeProtectedInternalMethod();
        }
    }
}</pre>
<pre class="c-sharp" name="code">// Assemby : B
using AssemblyA;
namespace AssemblyB
{
    class B : A
    {
        public string SomeMethod() {
            // We can access the method because
            // it's inherited by A2
            // despite the different assembly
            return SomeProtectedInternalMethod();
        }
    }

    class B2
    {
        public string SomeMethod()
        {
            A AI = new A();
            // We can't access the method
            // through the class instance
            // because it's different assembly
            return AI.SomeProtectedInternalMethod();
        }
    }
}</pre>
<p>So, if we will try to compile AssemblyB we&#8217;ll get an error in line 23 that says : <span style="color: #ff0000;">AssemblyA.A.SomeProtectedInternalMethod()&#8217; is inaccessible due to its protection level</span></p>
<p>I hope this explains once and for all the meaning of &#8220;protected internal&#8221; access modifier.</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.8" /></div><div>Rating: 4.8/<strong>5</strong> (15 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F06%2Fcshar-protected-internal%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/06/cshar-protected-internal/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>C# Inheritance Question</title>
		<link>http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/</link>
		<comments>http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 21:39:33 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[main string]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[Overloading]]></category>
		<category><![CDATA[public static string]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[simple questions]]></category>
		<category><![CDATA[string result]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=191</guid>
		<description><![CDATA[The following are two simple questions related to C# inheritance. Please try to give an answer without executing the code, otherwise where is the fun part ? // Question #1 class Program { static void Main(string[] args) { int i = 13; string Result = B.Get(i); Console.WriteLine(Result); } } public class A { public static [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>The following are two simple questions related to C# inheritance.<br />
Please try to give an answer without executing the code, otherwise where is the fun part ?<br />
<span id="more-191"></span></p>
<pre class="c-sharp" name="code">
    // Question #1
    class Program
    {
        static void Main(string[] args)
        {
            int i = 13;
            string Result = B.Get(i);
            Console.WriteLine(Result);
        }
    }

    public class A
    {
        public static string Get(int Value) {
            return "A";
        }
    }

    public class B : A
    {
        public static string Get(float Value)
        {
            return "B";
        }
    }
</pre>
<pre class="c-sharp" name="code">
    // Question #2
    class Program
    {
        static void Main(string[] args)
        {
            int i = 13;
            string Result = B.Get(i);
            Console.WriteLine(Result);
        }
    }

    public class B
    {
        public static string Get(float Value)
        {
            return "B";
        }

        public static string Get(int Value) {
            return "A";
        }
    }
</pre>
<p>What will be the result of the above code parts ?</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F06%2Fcsharp-inheritance-question%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

