メンバ変数の場合
using System.Collections.Generic;
public class Program
{
public Dictionary<int, string> m_table1 = new Dictionary<int, string>
{
{ 1, "フシギダネ" },
{ 2, "フシギソウ" },
{ 3, "フシギバナ" },
};
public Dictionary<int, string> m_table2 = new Dictionary<int, string>
{
[ 1 ] = "フシギダネ",
[ 2 ] = "フシギソウ",
[ 3 ] = "フシギバナ",
};
}
ローカル変数の場合
using System.Collections.Generic;
public class Example
{
public void Hoge()
{
var table1 = new Dictionary<int, string>();
table1.Add( 1, "フシギダネ" );
table1.Add( 2, "フシギソウ" );
table1.Add( 3, "フシギバナ" );
var table2 = new Dictionary<int, string>
{
{ 1, "フシギダネ" },
{ 2, "フシギソウ" },
{ 3, "フシギバナ" },
};
var table3 = new Dictionary<int, string>
{
[ 1 ] = "フシギダネ",
[ 2 ] = "フシギソウ",
[ 3 ] = "フシギバナ",
};
}
}