ソースコード
using System.Collections.Generic; public static class Program { private static void Main() { var table = new Dictionary<int, string> { { 1, "フシギダネ" }, { 2, "フシギソウ" }, { 3, "リザードン" }, }; // OK table[ 3 ] = "フシギバナ"; // NG(例外が発生する) // table.Add( 3, "フシギバナ" ); } }
- Add 関数ではなくインデクサを使用します