Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:03:16+00:00 2026-05-25T11:03:16+00:00

Assume I have a class C that inherits from 2 interfaces ( I1 and

  • 0

Assume I have a class C that inherits from 2 interfaces (I1 and I2). I also have two versions of a method (DoStuff), each taking one of the interfaces as a parameter. If I call DoStuff(C), which one gets called?

interface I1 { ... }
interface I2 { ... }
class C : I1, I2 { ... }

int DoStuff(I1 target) { ... }
int DoStuff(I2 target) { ... }

//What gets called here?
C target = new C()
DoStuff(target)

If I2 derives from I1, I think it’s relatively simple – the I2 version gets called. I’m interested in the case where the interfaces are independent.

Assume I can’t edit C, I1 or I2. And .NET 2.0 if that makes any difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:03:17+00:00Added an answer on May 25, 2026 at 11:03 am

    Neither gets called. If your two methods are overloads in the same class, the compiler does not attempt to disambiguate at all. It’ll simply not compile your code, saying it’s ambiguous between your two overloads as you declared target to be a type that implements both interfaces.

    If you declare target to be of one of the interface types, or cast it at call-time (as Jon shows), then there’s no ambiguity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a class called MyClass that has two properties (int Id and
I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class
I have a class that inherits from a base class and implements the following...
So assume I have a class that has an init method that does something
Assume I have a class A and a class B that is derived from
Assume I have a class that looks like this: class Sample { public string
So let's assume I have a class named ABC that will have a list
Assume that we have the following code: class Program { static volatile bool flag1;
Assume some domain and view objects (that have no common base class) public class
When speaking about casting here, I mean implicit cast. Assume class B inherits from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.