Internal or protected

Source: Internet
Author: User

Pop quiz for you C # developers out there. Will the following code compile?

//In Foo.dllpublic class Kitty{  protected internal virtual void MakeSomeNoise()  {    Console.WriteLine("I'm in ur serverz fixing things...");  }}//In Bar.dllpublic class Lion : Kitty{  protected override void MakeSomeNoise()  {    Console.WriteLine("LOL!");  }}

If you had asked me that yesterday, I wocould have said hell no. You can't override an internal method in another assembly.

Of course, I wowould have been WRONG!

Well the truth of the matter is, IWasWrong. This came up in an internal discussion in which I was unfairly complaining that certain methods I needed to override were internal. In fact, they wereprotected internal. Doesn't that mean that the method is bothprotected And internal?

Had I simply tried to override them, I wocould have learned that my assumption was wrong. For the record...

protected internalMeansprotected OR internal

It's very clear when you think of the keywords as the union of accessibility rather than the intersection. Thusprotected internalMeans the method is accessible by anything that can accessprotectedMethod UNION with anything that can accessinternalMethod.

As the old saying goes, when you assume, you makeAssOutUAndMe. I never understood this saying because when I assume, I only make an ass of me. I really think the word shoshould simply beAssme. As in...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.