Why C# calls different overloaded method for different values of same type?

Posted by Fabio Veronez on Stack Overflow See other posts from Stack Overflow or by Fabio Veronez
Published on 2010-03-25T12:58:42Z Indexed on 2010/03/25 13:03 UTC
Read the original article Hit count: 358

Filed under:
|
|

Hello all,

I have one doubt concerning c# method overloading call resolution.

Let's suppose I have the following C# code:

enum MyEnum { Value1, Value2 }

public void test() {
    method(0); // this calls method(MyEnum)
    method(1); // this calls method(object)
}

public void method(object o) {
}

public void method(MyEnum e) {
}

Note that I know how to make it work but I would like to know why for one value of int (0) it calls one method and for another (1) it calls another. It sounds awkward since both values have the same type (int) but they are "linked" for different methods.

Ps.: This is my first question here, i'm sorry if I made something wrong. =P

© Stack Overflow or respective owner

Related posts about c#

Related posts about method-overloading