How does the method overload resolution system decide which method to call when a null value is passed?

Posted by Joan Venge on Stack Overflow See other posts from Stack Overflow or by Joan Venge
Published on 2011-03-02T20:56:08Z Indexed on 2011/03/02 23:25 UTC
Read the original article Hit count: 303

Filed under:
|
|

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).

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET