The declaration problem of mixed inheritance between base class and interface

Source: Internet
Author: User
Tags inheritance mixed

1. The problem is at first

Today, looking at the feedback from the article "Interface inheritance declaration issues", I found that ninputer left such a question:

If there is

Class A:interface1

So

Class B:a, Inteface1

And

Class B:a

What would be the difference? What does the compiler do with the IL level to achieve this functionality?

2. Exploring Questions & Understanding issues

The process of solving a problem is both a process of exploration and a process of reasoning and argumentation. OK, I'm going to try to use contradiction to explore this problem.

First, I assume that the two types of inheritance of Class B in the question have the same effect and try to find them differently. To understand the effects of both approaches, I added the above code to complete:

interface IC { }
class A : IC { }
class B1 : A { }
class B2 : A, IC { }
class Program
{
  static void Main()
  {
    A a = new A();
    B1 b1 = new B1();
    B2 b2 = new B2();
    Console.WriteLine(a is IC);
    Console.WriteLine(b1 is A);
    Console.WriteLine(b1 is IC);
    Console.WriteLine(b2 is A);
    Console.WriteLine(b2 is IC);
  }
}

The results of the code run are:

True
True
True
True
True

Related Article

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.