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 4028472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:13:28+00:00 2026-05-20T11:13:28+00:00

So for instance you have a type like: public class EffectOptions { public EffectOptions

  • 0

So for instance you have a type like:

public class EffectOptions
{
    public EffectOptions ( params object [ ] options ) {}

    public EffectOptions ( IEnumerable<object> options ) {}

    public EffectOptions ( string name ) {}

    public EffectOptions ( object owner ) {}

    public EffectOptions ( int count ) {}

    public EffectOptions ( Point point ) {}

}

Here I just give the example using constructors but the result will be the same if they were non-constructor methods on the type itself, right?

So when you do:

EffectOptions options = new EffectOptions (null);

which constructor would be called, and why?

I could test this myself but I want to understand how the overload resolution system works (not sure if that’s what it’s called).

  • 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-20T11:13:29+00:00Added an answer on May 20, 2026 at 11:13 am

    For the exact rules, see the overload resolution spec. But briefly, it goes like this.

    First, make a list of all the accessible constructors.

    public EffectOptions ( params object [ ] options )
    public EffectOptions ( IEnumerable<object> options ) 
    public EffectOptions ( string name )
    public EffectOptions ( object owner ) 
    public EffectOptions ( int count ) 
    public EffectOptions ( Point point )
    

    Next, eliminate all the inapplicable constructors. An applicable constructor is one where every formal parameter has a corresponding argument, and the argument is implicitly convertible to the formal parameter type. Assuming that Point is a value type, we eliminate the “int” and “Point” versions. That leaves

    public EffectOptions ( params object[] options )
    public EffectOptions ( IEnumerable<object> options ) 
    public EffectOptions ( string name )
    public EffectOptions ( object owner ) 
    

    Now, we have to consider whether the one with “params” is applicable in its expanded or unexpanded form. In this case it is applicable in both forms. When that happens, we discard the expanded form. So that leaves

    public EffectOptions ( object[] options )
    public EffectOptions ( IEnumerable<object> options ) 
    public EffectOptions ( string name )
    public EffectOptions ( object owner ) 
    

    Now we must determine the best of the applicable candidates. The bestness rules are complicated, but the short version is that more specific is better than less specific. Giraffe is more specific than Mammal, Mammal is more specific than Animal, Animal is more specific than object.

    The object version is less specific than all of them, so it can be eliminated. The IEnumerable<object> version is less specific than the object[] version (do you see why?) so it can be eliminated too. That leaves

    public EffectOptions ( object[] options )
    public EffectOptions ( string name )
    

    And now we are stuck. object[] is neither more nor less specific than string. Therefore this gives an ambiguity error.

    That is just a brief sketch; the real tiebreaking algorithm is much more complicated. But those are the basics.

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

Sidebar

Related Questions

For a type like this: public class BlurEffect { public const string Name =
I have some code like this: public class EffectValues : IEnumerable<object> { public object
I have a class something like: public class Section { private IEnumerable<Section> sections; private
Assuming I have a class like public class FooImpl { public void bar(){}; }
I have the Global.asax like the code below: public class MvcApplication : System.Web.HttpApplication {
I have a java class that looks like public class MyClass { private final
I have a class hierarchy like this public abstract class CalendarEventBase{} public class TrainingEvent
So let's say I have something like this: public class Service : IService {
I have an object instance which I access with the ME as it accesses
Given a class: [DataContract] public sealed class ChangedField { [DataMember(Name=I)] public ushort FieldId {

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.