C# typed function not propagating type to method call

Viewed 35

If I have the class

public class MyClass
    {
        int MyProp { get; set; }

        public MyClass(int val)
        {
            MyProp = val;
        }

        public bool Equals(MyClass obj)
        {
            return MyProp == obj.MyProp;
        }
    }

and the function

bool MyFunc<T>(T obj1, T obj2)
{
    return obj1.Equals(obj2);
}

Why when I call, MyFunc(new MyClass(1), new MyClass(2)) is MyClass.Equals(MyClass obj) not invoked?

I know that I must be missing a crticial piece of the puzzle here, but I am not sure what. The function infers the type by the arguments, so it knows it is dealing with MyClass objects...

0 Answers
Related