Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created November 3, 2020 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/ab662589c3c375dcee4e704cdf9adddc to your computer and use it in GitHub Desktop.
Save todorok1/ab662589c3c375dcee4e704cdf9adddc to your computer and use it in GitHub Desktop.
C#のDictionaryでキーが重複した時のエラー
// Addメソッドで値を追加します。
itemDict.Add(1, "ポーション");
itemDict.Add(2, "ハイポーション");
itemDict.Add(3, "エーテル");
itemDict.Add(3, "エクスポーション");
// キー 3 は既に辞書に追加されているのでエラーになります。
// コンソールでは以下のように表示されます。
// ArgumentException: An item with the same key has already been added. Key: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment