JetBrains Rider 2026.2 Help

コードインスペクション:値タプル 'GetHashCode()' は一部の要素を無視します

このインスペクションは、8 個を超えるコンポーネントを持つ値タプルへの GetHashCode() 呼び出しを報告します。 このようなタプルの場合、値タプルのハッシュコードは最後の 8 個のコンポーネントからのみ計算されるため、最初のコンポーネントは結果に寄与しません。 すべての値を明示的に含めるハッシュコード計算を使用してください。

サンプル

using System; public sealed class OrderKey( int customerId, int regionId, int year, int month, int day, int productId, int channelId, int campaignId, int version) { public override int GetHashCode() { return (customerId, regionId, year, month, day, productId, channelId, campaignId, version).GetHashCode(); } }
using System; public sealed class OrderKey( int customerId, int regionId, int year, int month, int day, int productId, int channelId, int campaignId, int version) { public override int GetHashCode() { var hashCode = new HashCode(); hashCode.Add(customerId); hashCode.Add(regionId); hashCode.Add(year); hashCode.Add(month); hashCode.Add(day); hashCode.Add(productId); hashCode.Add(channelId); hashCode.Add(campaignId); hashCode.Add(version); return hashCode.ToHashCode(); } }

修正方法

このインスペクションには専用のクイックフィックスはありません。 タプルベースのハッシュコードを、すべてのコンポーネントを含めた明示的な HashCode 計算に置き換えてください。

2026 年 7 月 17 日