Misunderstood common concepts in your programming language

As we all know we have a range of access modifiers in C#: public, protected, internal and private. These can be used as a single word or in a single case be combined: that is internal protected (and the other way around protected internal).

During a conversation with a friend yesterday regarding naming of intance variables we ended up discussing the internal protected modifier and I argued that it meant that it was internal or protected while my friend figured it meant internal and protected. That is he wouldn't believe that it could be accessed from a subclass outside the assembly. I was a bit shaky in my belief as it isn't the access-modifier i use the most, so the documentation to the help. And in the single line describing it the word or is used.

I asked three other people who work with C# at a daily baiss, and none of the three answered that i could access an internal protected method/property/etc. from outside the assembly. So to clarify the following code would be valid even though the two namespaces are in different assemblies:

//Assembly 1
namespace MyFirstNamespace{
	public class MyFirstClass {
		internal protected void MyMethod(){
			//Implementation
		}
	}
}

//Assembly 2
namespace MySecondNamespace{
	public class MySecondClass : MyFirstClass{
		public void MySecondMethod(){
			this.MyMethod();
		}
	}
}
Posted on 22 Nov 2007 by Jakob T. Andersen
blog comments powered by Disqus