概要
System.HashCode
を使用すると GetHashCode を簡単に実装できる
using System; using UnityEngine; public sealed class Character { public int Id { get; } public string Name { get; } public Character ( int id, string name ) { Id = id; Name = name; } public override int GetHashCode() { return HashCode.Combine( Id, Name ); // var hashCode = new HashCode(); // hashCode.Add( Id ); // hashCode.Add( Name ); // return hashCode.ToHashCode(); } } public sealed class Example : MonoBehaviour { private void Start() { var character = new Character( 25, "ピカチュウ" ); Debug.Log( character.GetHashCode() ); } }