doutuo8800 2019-04-06 21:54
浏览 176
已采纳

从php到c#:字典数组,或字典词典?

I'm a newbie at programming. I have this php code, it's basically used for translating some sentences from txt files:

$LANG = array();

$LANG['en'] = array(
    11 => "Name",
    20 => "Surname",
    21 => "Age",
    22 => "Profession",
);
$LANG['es'] = array(
    11 => "Nombre",
    20 => "Apellido",
    21 => "Edad",
    22 => "Profesión",
);

I'm trying to do the same in c#, something like this:

Dictionary<int, string>[] LANG = new Dictionary<int, string>[]
        {
        new Dictionary<int, string>(),
        LANG['en']=new Dictionary<int, string>()
             {
                 {11, "Name"},
                 {20, "Surname"},
                 {21, "Age"},
                 {22, "Profession"}
             },
        LANG['es']=new Dictionary<int, string>()
             {
                 {11, "Nombre"},
                 {20, "Apellido"},
                 {21, "Edad"},
                 {22, "Profesión"}
             }
        };

1) Is this c# doing exactly the same as the php code? Should i do an array of dictionaries, or should i do a dictionary of dictionaries?

2) For LANG['en'] and LANG['es'], i'm getting the error message "A field initializer cannot reference the non-static field, method or property 'Form1.LANG'. What am i doing wrong?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥100 AZURE创建地图类webapp
      • ¥20 51单片机实训实验报告
      • ¥15 C# 循环读写数据中途突然变慢
      • ¥15 用Java实现双端队列
      • ¥150 ID3决策树实现分类
      • ¥15 multisim10安装后,找不到NI License Manager的程序来安装许可证
      • ¥15 C++银行卡系统 Help!
      • ¥15 R语言数据分析的相关问题
      • ¥15 模型导入SP后贴图纹理只有一个,拆了四张UV的,怎么解决?
      • ¥15 检索带order by 非常慢