Can't override GetHashCode (cannot change return type when overriding method int UnityEngine.Object.GetHashCode")

StackOverflow https://stackoverflow.com/questions/18263257

문제

I'm using C# in Unity3D game engine. in my MonoBehaviour script I need to override GetHashCode. But whenever I do, I get the error cannot change return type when overriding method int UnityEngine.Object.GetHashCode" (Isn't GetHashCode located inside the System namespace?)

My overriding:

public override int GetHashCode()
{
    return index.GetHashCode();
}

The error no longer exists if I remove the using UnityEngine; header from the top. I tried to explicitly tell it what to override, it's not like dealing with interfaces, so it didn't work.

What's going on here, are there two GetHashCodes? how can I override GetHashCode here?

Thanks.

EDIT: I have removed the using System; and left out UnityEngine, same result.

EDIT: I also tried an empty class, and another project, nothing :(

도움이 되었습니까?

해결책 3

Solved. Sorry for the confusion guys, it was a Resharper false error. There was nothing wrong with my code. Thanks for anybody who tried to help.

다른 팁

UnityEngine.Object has its own GetHashCode() and to overwrite it you simply do what you've done above, except the return type you have there is wrong. See below:

public class Test : MonoBehaviour {
    public override int GetHashCode() {
        return base.GetHashCode();
    }
}

.Net can't understand which Object you are using.

using Object=System.Object;

try this

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top